mysql using the new method uses the start slave until recovery from the library

After the drop in high-risk MySQL misuse recovery methods

Purpose:

  • The drop experiment to resume operation as an example, using different methods for recovery of erroneous data.
  • 1. Environment

  • mysql 5.7.23-log
  • master db210(192.168.99.210)
  • slave db212(192.168.99.212)
  • Idle server: db211 (192.168.99.211)
  • Pressure: The process used to do this experiment, the use of reading and writing analogue pressure while doing sysbench (28thread + 10 * 100000 rows)

2. In this study, the pre-conditions:

  • At least one full backup before drop
  • Prepared to drop from full operational point in time there is full binlog, and binlog format = 'row'
    if no more than two backup how to do? See "mistake-free backup recovery method"

3. Analog misuse

root@localhost [wenyz]>select count(*) from t2;
+----------+
| count(*) |
+----------+
|  163818 |
+----------+
1 row in set (0.12 sec)

root@localhost [wenyz]>drop table t2;
Query OK, 0 rows affected (0.02 sec)

root@localhost [wenyz]>show master status;
+------------------+-----------+--------------+------------------+------------------------------------------------+
| File            | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                              |
+------------------+-----------+--------------+------------------+------------------------------------------------+
| mysql-bin.000020 | 136445791 |              |                  | 9e912d2b-92f6-11e8-9747-0050568be82c:1-9872111 |
+------------------+-----------+--------------+------------------+------------------------------------------------+
1 row in set (0.00 sec)

root@localhost [wenyz]>flush logs;
Query OK, 0 rows affected (1.41 sec)

 

4. Prior to the experiment different methods to complete the following steps:

  • Copy the full backup and all binlog files to idle servers: the db211
  • Preparation of a full return to the temporary new instance (temporary slave).

5. Locate the erroneous position (or GTID binlog pos)

By looking doubt the binlog: 
[db210_19 the root @: . 11 : 07 / Data / 57mysql / mysql3506 / logs] 
#ll 
Total 75,564,544 
-rw-R & lt ----- . 1 MySQL MySQL        177 Jul- 29  14 : 14 MySQL-bin. 000001 
...
 -rw-R & lt ----- . 1 MySQL MySQL   39,336,996 Jul- 29  . 19 : 12 is MySQL-bin. 000020 
-rw-R & lt ----- . 1 MySQL MySQL      13340 Jul- 29  . 19 : 12 is MySQL- bin.index
[@ db210_19 the root: 12 is : 48 / Data / 57mysql / mysql3506 / logs] 

the binlog file export command: 
#mysqlbinlog -v --base64 = Auto-Output / Data / 57mysql / mysql3506 / logs / MySQL-bin. 000020 > / Data / Backup / 20 .sql 
binlog file export find: DROP TABLE `t2`: 

in MySQL - find the corresponding position in bin.000020: 
# aT 97,871,478 
# 180 731  19 : 33 : 29 Server the above mentioned id 1,853,506   end_log_pos 97,871,543 CRC32 0x8cd4354d        GTID last_committed = 205567    sequence_number = 205.57 thousand  rbr_only=no     original_committed_timestamp=0  immediate_commit_timestamp=0    transaction_length=0
# original_commit_timestamp=0 (1970-01-01 08:00:00.000000 CST)
# immediate_commit_timestamp=0 (1970-01-01 08:00:00.000000 CST)
/*!80001 SET @@session.original_commit_timestamp=0*//*!*/;
SET @@SESSION.GTID_NEXT= '9e912d2b-92f6-11e8-9747-0050568be82c:9791090'/*!*/;
# at 97871543
#180731 19:33:29 server id 1853506  end_log_pos 97871660 CRC32 0x974a86d8       Query   thread_id=35    exec_time=0     error_code=0
use `wenyz`/*!*/;
SET TIMESTAMP=1533036809/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
DROP TABLE `t2` /* generated by server */
/*!*/;
# at 97871660
#180731 19:33:29 server id 1853506  end_log_pos 97871725 CRC32 0xb85257d6       GTID    last_committed=205567   sequence_number=205571  rbr_only=yes    original_committed_timestamp=0  immediate_commit_timestamp=0    transaction_length=0
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
# original_commit_timestamp=0 (1970-01-01 08:00:00.000000 CST)
# immediate_commit_timestamp=0 (1970-01-01 08:00:00.000000 CST)
/*!80001 SET @@session.original_commit_timestamp=0*//*!*/;
SET @@SESSION.GTID_NEXT= '9e912d2b-92f6-11e8-9747-0050568be82c:9791091'/*!*/;
# at 97871725

 

6. a recovery method:

  • Library constructed from the master, and by: start slave sql_thread until sql_before_gtids = '9e912d2b-92f6-11e8-9747-0050568be82c: 9791090' test set SQL stopped at a playback position prior to transaction drop operation.
  • Executed_Gtid_Set should stop at: 9e912d2b-92f6-11e8-9747-0050568be82c: 1-9791089
change master to master_host='db210',master_port=3506,master_user='wyz',master_password='xxxx',master_auto_position=1;
root@localhost [(none)]>start slave io_thread ;
Query OK, 0 rows affected (0.01 sec)

root@localhost [(none)]>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: db210
                  Master_User: wyz
                  Master_Port: 3506
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000015
          Read_Master_Log_Pos: 10476294
               Relay_Log_File: relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: 
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 27669048
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1853506
                  Master_UUID: 9e912d2b-92f6-11e8-9747-0050568be82c
             Master_Info_File: /data/57mysql/mysql3506/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 9e912d2b-92f6-11e8-9747-0050568be82c:6730274-6788383
            Executed_Gtid_Set: 9e912d2b-92f6-11e8-9747-0050568be82c:1-6730273
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

root@localhost [(none)]>
root@localhost [(none)]>start slave sql_thread until sql_before_gtids='9e912d2b-92f6-11e8-9747-0050568be82c:9791090';
Query OK, 0 rows affected (0.00 sec)

 

View sql_thread execution stopped at the position 9,791,089

 

root@localhost [(none)]>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: db210
                  Master_User: wyz
                  Master_Port: 3506
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000079
          Read_Master_Log_Pos: 15969193
               Relay_Log_File: relay-bin.000024
                Relay_Log_Pos: 97871691
        Relay_Master_Log_File: mysql-bin.000020
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 97871478
              Relay_Log_Space: 15602695666
              Until_Condition: SQL_BEFORE_GTIDS
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1853506
                  Master_UUID: 9e912d2b-92f6-11e8-9747-0050568be82c
             Master_Info_File: /data/57mysql/mysql3506/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 9e912d2b-92f6-11e8-9747-0050568be82c:6730274-42357224
            Executed_Gtid_Set: 9e912d2b-92f6-11e8-9747-0050568be82c:1-9791089
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

root@localhost [(none)]>

 

See if the same data and drop:

 

root@localhost [(none)]>select count(*) from wenyz.t2;
+----------+
| count(*) |
+----------+
|   163818 |
+----------+
1 row in set (0.10 sec)

root@localhost [(none)]>

 

The data table deriving

/usr/local/mysql57/bin/mysqldump -S /tmp/mysql3506.sock -pxxxx --master-data=2 --single-transaction wenyz t2 >/data/backup/t2.sql

 

The t2.sql back to master and import

[root@db211_20:49:35 /root]  
scp /data/backup/t2.sql db210:/data/backup/t2.sql               


[root@db211_20:50:10 /root] #/usr/local/mysql57/bin/mysql -S /tmp/mysql3506.sock -pxxxx <t2.sql
mysql: [Warning] Using a password on the command line interface can be insecure.


root@localhost [wenyz]> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 163818 |
+----------+
1 row in set (0.40 sec)

 

Excerpt:  https://www.cnblogs.com/2woods/p/9394614.html

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/fengjian2016/p/12456170.html