Preface
 
    How to rescue a dropped or truncated table online?Dropping or truncating is ddl operation which cannot be flashed back by the populare flashback tools like MyFlash,binlog2mysql,mysqldump_backup,etc.Therefore,the conventional method is restoring the database to a newly initialized instance on another server with backup(physical or logical).Whatif the backup set is rather huge for example the mysqldump backup is more than 200G?It will cost a long time to rescue the dropped table back.Is there an effective way to accomplish the issue?Let's see the tests below.
 
Framework
 
Hostname IP/Port Identity OS Version MySQL Version GTID Mode Binlog Format
zlm2 192.168.1.101/3306 master CentOS 7.0 5.7.21 on row
zlm3 192.168.1.102/3306 slave CentOS 7.0 5.7.21 on row
 
Precedure
 
Test1:Rescue a table after dropping it based on a new mysqldump backup.
 
Generate the test data with sysbench.
 [root@zlm2 :: ~/sysbench-1.0/src/lua]
#sysbench oltp_read_write.lua --mysql-host=192.168.1.101 --mysql-port= --mysql-user=zlm --mysql-password=zlmzlm --mysql-db=sysbench --tables= --table-size= --mysql-storage-engine=innodb prepare
sysbench 1.0. (using bundled LuaJIT 2.1.-beta2) Creating table 'sbtest1'...
Inserting records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
Inserting records into 'sbtest5'
Creating a secondary index on 'sbtest5'...
Creating table 'sbtest6'...
Inserting records into 'sbtest6'
Creating a secondary index on 'sbtest6'...
Creating table 'sbtest7'...
Inserting records into 'sbtest7'
Creating a secondary index on 'sbtest7'...
Creating table 'sbtest8'...
Inserting records into 'sbtest8'
Creating a secondary index on 'sbtest8'...
Creating table 'sbtest9'...
Inserting records into 'sbtest9'
Creating a secondary index on 'sbtest9'...
Creating table 'sbtest10'...
Inserting records into 'sbtest10'
Creating a secondary index on 'sbtest10'... (zlm@192.168.1.101 )[sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest1 |
| sbtest10 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+--------------------+
rows in set (0.00 sec)
Backup the database sysbench with mysqldump.
 [root@zlm2 :: ~]
#mysqldump --single-transaction --master-data= -A > db3306_`date +%Y%m%d`.sql
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. [root@zlm2 :: ~]
#ls -l
total
drwxr-xr-x root root Jul :
-rw-------. root root Jul anaconda-ks.cfg
-rw-r--r-- root root Jul : db3306_20180726.sql
-rw-r--r-- root root Jul : db.sql
-rwxr-xr-x root root Jun : mysqld.sh
-rwxr-xr-x root root Jul : percona-xtrabackup--2.4.-.el7.x86_64.rpm
drwxr-xr-x root root Jul : sysbench-1.0 [root@zlm2 :: ~]
#scp db3306_20180726.sql zlm3:/data/backup
root@zlm3's password:
db3306_20180726.sql % 19MB .5MB/s : [root@zlm2 :: ~]
Drop one table in database "sysbench".
 
 (zlm@192.168.1.101 )[sysbench]>drop table sbtest10;
Query OK, rows affected (0.01 sec) (zlm@192.168.1.101 )[sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest1 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+--------------------+
rows in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>
Create a rescue environment in an initialized instance on zlm3.
 (zlm@192.168.1.102 )[(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) (zlm@192.168.1.102 )[(none)]>create database sysbench; //Create a same name database.
Query OK, row affected (0.00 sec) (zlm@192.168.1.102 )[(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| sysbench |
+--------------------+
rows in set (0.00 sec) (zlm@192.168.1.102 )[(none)]>create user rescue@'192.168.1.%' identified by 'rescue'; //Create a rescue user called "rescue".
Query OK, rows affected (0.00 sec) (zlm@192.168.1.102 )[(none)]>grant all privileges on sysbench.sbtest10 to rescue@'192.168.1.%'; //Grant privileges to user ""rescue.
ERROR (): GRANT command denied to user 'zlm'@'zlm3' for table 'sbtest10' //It seems current user does not has the privilege to grant.
(zlm@192.168.1.102 )[(none)]>exit
Bye [root@zlm3 :: ~]
#mysql -uroot -pPassw0rd -hlocalhost -S /tmp/mysql3306.sock //Login with root user.
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (root@localhost mysql3306.sock)[(none)]>grant all privileges on sysbench.sbtest10 to rescue@'192.168.1.%'; //Grant privileges again.It works.
Query OK, rows affected (0.00 sec)
Check the backup set and import it.
 [root@zlm3 :: /data/backup]
#ls -l|grep db3306
-rw-r--r-- root root Jul : db3306_20180726.sql [root@zlm3 :: /data/backup]
#mysql -urescue -prescue -h192.168.1. -P3306 -f < db3306_20180726.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR () at line : Access denied; you need (at least one of) the SUPER privilege(s) for this operation
ERROR () at line : Access denied; you need (at least one of) the SUPER privilege(s) for this operation
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'mysql'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'mysql'
ERROR (3D000) at line : No database selected //A bundle of "No database seelcted" message has been omitted. ERROR (3D000) at line : No database selected
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest1'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest1'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest1'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest1'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest1'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest1'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest2'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest2'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest2'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest2'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest2'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest2'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest3'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest3'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest3'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest3'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest3'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest3'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest4'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest4'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest4'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest4'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest4'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest4'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest5'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest5'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest5'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest5'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest5'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest5'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest6'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest6'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest6'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest6'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest6'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest6'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest7'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest7'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest7'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest7'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest7'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest7'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest8'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest8'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest8'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest8'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest8'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest8'
ERROR () at line : DROP command denied to user 'rescue'@'zlm3' for table 'sbtest9'
ERROR () at line : CREATE command denied to user 'rescue'@'zlm3' for table 'sbtest9'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'sysbench'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest9'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest9'
ERROR () at line : INSERT command denied to user 'rescue'@'zlm3' for table 'sbtest9'
ERROR () at line : ALTER command denied to user 'rescue'@'zlm3' for table 'sbtest9'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'zlm'
ERROR () at line : Access denied for user 'rescue'@'192.168.1.%' to database 'zlm'
ERROR () at line : Access denied; you need (at least one of) the SUPER privilege(s) for this operation //The other tables in backup set will be skipped except for table "sbtest10".
Check the rescued table "sbtest10".
 (root@localhost mysql3306.sock)[(none)]>use sysbench
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
(root@localhost mysql3306.sock)[sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest10 |
+--------------------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>select count(*) from sbtest10;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) //Because the dropping operation is just happened after my backing up with mysqldump.There's no need to backup the incremental data in the dropped table.
//Therefore,we can simply copy the table back with transportable tablespace method,which can be referred to my previous blog.
Test2:Rescue a table after truncating it based on a old mysqldump backup plus binlog.
 
Execute several normal dml operations in table "sbtest9".
 (zlm@192.168.1.101 )[sysbench]>select count(*) from sbtest9;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>delete from sbtest9 limit ;
Query OK, rows affected (0.07 sec) (zlm@192.168.1.101 )[sysbench]>select count(*) from sbtest9;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>flush logs;
Query OK, rows affected (0.04 sec) (zlm@192.168.1.101 )[sysbench]>delete from sbtest9 limit ;
Query OK, rows affected (0.04 sec) (zlm@192.168.1.101 )[sysbench]>select count(*) from sbtest9;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>flush logs;
Query OK, rows affected (0.02 sec)
Truncate the table to mimic the miss operation.
 (zlm@192.168.1.101 )[sysbench]>truncate table sbtest9;
Query OK, rows affected (0.02 sec) (zlm@192.168.1.101 )[sysbench]>select count(*) from sbtest9;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>show master status;
+------------------+----------+--------------+------------------+------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------------+
| mysql-bin. | | | | 1b7181ee-6eaf-11e8-998e-080027de0e0e:- |
+------------------+----------+--------------+------------------+------------------------------------------------+
row in set (0.00 sec)
Clear the environment and grant the right privileges.
 (root@localhost mysql3306.sock)[sysbench]>drop table sbtest10;
Query OK, rows affected (0.03 sec) (root@localhost mysql3306.sock)[sysbench]>revoke all privileges on sysbench.sbtest10 from rescue@'192.168.1.%';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>grant all privileges on sysbench.sbtest9 to rescue@'192.168.1.%';
Query OK, rows affected (0.00 sec)
Restore the table "sbtest9" from mysqldump backup.
 [root@zlm3 :: /data/backup]
#mysql -urescue -prescue -h192.168.1. -P3306 -f < db3306_20180726.sql ... //Omitted. (root@localhost mysql3306.sock)[sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest9 |
+--------------------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>select count(*) from sbtest9;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) //On account of restoring from an old mysqldump backup,we cannot rescue the incremental data in the table "sbtest9".
//What can we do next step?Those incremental data are all in the binlog,so we need to implement a slave first.
Implement a slave filter replication on zlm3.
 //Fetch the gtid_purged infomation from mysqldump backup.
[root@zlm3 :: /data/backup]
#grep "SET @@GLOBAL.GTID_PURGED" db3306_20180726.sql
SET @@GLOBAL.GTID_PURGED='1b7181ee-6eaf-11e8-998e-080027de0e0e:1-3730210'; (root@localhost mysql3306.sock)[sysbench]>reset master;
Query OK, rows affected (0.01 sec) (root@localhost mysql3306.sock)[sysbench]>reset slave;
Query OK, rows affected (0.02 sec) (root@localhost mysql3306.sock)[sysbench]>show slave status\G
*************************** . row ***************************
Slave_IO_State:
Master_Host: 192.168.1.101
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File:
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File:
Slave_IO_Running: No
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
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:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 1b7181ee-6eaf-11e8-998e-080027de0e0e
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) //Set gtid_purged variable.
(root@localhost mysql3306.sock)[sysbench]>SET @@GLOBAL.GTID_PURGED='1b7181ee-6eaf-11e8-998e-080027de0e0e:1-3730210';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>show slave status\G
*************************** . row ***************************
Slave_IO_State:
Master_Host: 192.168.1.101
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File:
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File:
Slave_IO_Running: No
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
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:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 1b7181ee-6eaf-11e8-998e-080027de0e0e
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:- //After set @@global.gtid_purged operation,Executed_Gitd_Set will contain it.
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) //Start IO Thread.
(root@localhost mysql3306.sock)[sysbench]>start slave io_thread;
Query OK, rows affected (0.01 sec) (root@localhost mysql3306.sock)[sysbench]>show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.101
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin. //The newly binlog has been pulled to local server.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File:
Slave_IO_Running: Yes //The IO Thread working normally.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
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:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 1b7181ee-6eaf-11e8-998e-080027de0e0e
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:- //The newest gtid information has been got(3730211-3730214).
Executed_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) //Specify the replication filter only for table "sbtest9".
(root@localhost mysql3306.sock)[sysbench]>CHANGE REPLICATION FILTER REPLICATE_DO_TABLE = (sysbench.sbtest9);
Query OK, rows affected (0.00 sec) //Analyze the binlog on master to find out the right postion of gtid_set.
[root@zlm2 :: ~]
#mysqlbinlog -v --base64-output=decode-rows /data/mysql/mysql3306/logs/mysql-bin. > .log [root@zlm2 :: ~]
#cat .log
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at
# :: server id end_log_pos Start: binlog v , server v 5.7.-log created ::
# Warning: this binlog is either in use or was not closed properly.
# at
# :: server id end_log_pos Previous-GTIDs
# 1b7181ee-6eaf-11e8-998e-080027de0e0e:-
# at
# :: server id end_log_pos GTID last_committed= sequence_number= rbr_only=no
SET @@SESSION.GTID_NEXT= '1b7181ee-6eaf-11e8-998e-080027de0e0e:3730214'/*!*/;
# at
# :: server id end_log_pos Query thread_id= exec_time= error_code=
use `sysbench`/*!*/;
SET TIMESTAMP=/*!*/;
SET @@session.pseudo_thread_id=/*!*/;
SET @@session.foreign_key_checks=, @@session.sql_auto_is_null=, @@session.unique_checks=, @@session.autocommit=/*!*/;
SET @@session.sql_mode=/*!*/;
SET @@session.auto_increment_increment=, @@session.auto_increment_offset=/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=,@@session.collation_connection=,@@session.collation_server=/*!*/;
SET @@session.lc_time_names=/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
truncate table sbtest9 //Here's the truncate operation,we are supposed the sql_thread just stop before this operation.
/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; //Start SQL Thread using until clause.
(root@localhost mysql3306.sock)[sysbench]>start slave sql_thread until SQL_BEFORE_GTIDS='1b7181ee-6eaf-11e8-998e-080027de0e0e:3730214';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.101
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: sysbench.sbtest9 //Here's the "do table" option of replication filter.
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: SQL_BEFORE_GTIDS //Here's the option of until condition of start slave clause.
Until_Log_File:
Until_Log_Pos:
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:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 1b7181ee-6eaf-11e8-998e-080027de0e0e
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-
Executed_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) //Check the contents of rescued table.
(root@localhost mysql3306.sock)[sysbench]>select count(*) from sbtest9;
+----------+
| count(*) |
+----------+
| | //This is the correct number of records before we truncate the table on master.
+----------+
row in set (0.00 sec) //Likewise,we can copy the rescued table back to master in a proper certain time by transportable tablespace tech(I'm not going to demonstrate here).
Summary
  • There always be some miss operations such as drop,truncate which cannot be flashed back easily by tools.We should be careful to avoid them.
  • Onlyif you have a full database backup(mysqldump or Xtraback) and vital binlog,the destroyed table could be rescued.
  • The portion of recovering imcremental data also can be used in Xtrabackup method when rescuing lost data.
  • It's recommend to rename the rescued table before copying it back to the product database with transportable tablespace.
 

基于mysqldump备份集来恢复某个误操作的表(drop,truncate)的更多相关文章

  1. 基于Xtrabackup备份集来恢复某个误删除的表(drop)

      Preface       Yesterday,I've demonstratated how to rescue a droped and a truncated table based on ...

  2. 基于全备份+binlog方式恢复数据

    基于全备份+binlog方式恢复数据 将bkxt从库的全备份在rescs5上恢复一份,用cmdb操作 恢复全备后执行如下操作 set global read_only=OFF; stop slave; ...

  3. MySQL5.7下面,误操作导致的drop table db1.tb1; 的恢复方法:

    MySQL5.7下面,误操作导致的drop table db1.tb1; 的恢复方法: 0.停业务数据写入.[iptables封禁] 1.从备份服务器上拉取最新的一个全备文件,恢复到一个临时的服务器上 ...

  4. MySQL 基于mysqldump备份工具实战演练

    前言: 细节提示:先执行 show global variables like 'log_bin';看看log_bin的值,如果服务器变量log_bin的值为OFF,需要修改my.cnf配置文件,将l ...

  5. oracle数据库误操作把表删除了,怎样恢复

    一:表的恢复 对误删的表,只要没有使用PURGE永久删除选项,那么从flash back区恢复回来希望是挺大的.一般步骤有:1.从flash back里查询被删除的表 select * from re ...

  6. 028:基于mysqldump备份脚本

    MySQL Backup and Recovery 一 MySQL Backup 1.功能 mysqldump全量和增量备份,通过最近一次备份刷新产生binlog来定位执行增量. 脚本下载地址 git ...

  7. mysqldump 备份数据和恢复

    命令行下具体用法如下:  mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名; 一.导出数据: 导出整个数据库结构和数据mysqldump -h localhost -u ...

  8. 利用binlog server及Xtrabackup备份集来恢复误删表(drop)

      Preface       Today I'm gonna test how to rescue a dropped table from binlog server based on a ful ...

  9. 恢复被误操作删除的数据 fn_dblog

    -- Script Name: Recover_Deleted_Data_Proc -- Script Type : Recovery Procedure  -- Develop By: Muhamm ...

随机推荐

  1. SAP S4CRM和C4C的技术比较

    如果您对SAP S/4HANA for Customer Management(以下简称S4CRM)和SAP Cloud for Customer(以下简称C4C)不甚熟悉,那我建议您可以先浏览我之前 ...

  2. 解决Wamp各版本中 Apache 文件列表图标无法显示

    Edit the following file manually and change the path to the icons folder (it appears times in the fi ...

  3. mysql轮廓总结

    架构=数据类型.索引.分片.主从复制原理.数据备份 学习软件,都应该先从架构入手,每一层掌握就行.mysql难吗?从其架构层开始,就不难啦. 架构结构:http://www.cnblogs.com/h ...

  4. 将TIF格式批量转换成jpg或png格式(C#自制软件)

    此项目基于.net framework 4.0 全选tif,拖进去,等待,完成. so easy... 链接:https://pan.baidu.com/s/1uCDhAT0uHRjdy4g557wK ...

  5. 将matlab处理结果保存为图像文件

    imwrite(testIm, 'Data/Test/testIm.bmp', 'BMP');

  6. matlab的figure窗口命名为中文

    figure('NumberTitle', 'off', 'Name', '我的窗口名字');

  7. 注解@Component,@Controller,@Service,@Repository简单了解

    Spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring 的开发.@Repository注解便属于最先引入的一批,它用于将数据访问层 (DAO 层 ) 的类标识为 Spring B ...

  8. CUDA中多维数组以及多维纹理内存的使用

    纹理存储器(texture memory)是一种只读存储器,由GPU用于纹理渲染的图形专用单元发展而来,因此也提供了一些特殊功能.纹理存储器中的数据位于显存,但可以通过纹理缓存加速读取.在纹理存储器中 ...

  9. 第19章 通讯的基本概念—零死角玩转STM32-F429系列

    第19章     通讯的基本概念 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/firege ...

  10. 前端面试题(来自前端网http://www.qdfuns.com/notes/23515/c9163ddd620baac5dd23141d41982bb8.html)

    HTML&CSS 1. 常用那几种浏览器测试?有哪些内核(Layout Engine)? (Q1)浏览器:IE,Chrome,FireFox,Safari,Opera. (Q2)内核:Trid ...