基于mysqldump备份集来恢复某个误操作的表(drop,truncate)
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 |
[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)
[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 :: ~]
(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]>
(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)
[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".
(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.
(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)
(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)
(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)
[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.
//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).
- 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)的更多相关文章
- 基于Xtrabackup备份集来恢复某个误删除的表(drop)
Preface Yesterday,I've demonstratated how to rescue a droped and a truncated table based on ...
- 基于全备份+binlog方式恢复数据
基于全备份+binlog方式恢复数据 将bkxt从库的全备份在rescs5上恢复一份,用cmdb操作 恢复全备后执行如下操作 set global read_only=OFF; stop slave; ...
- MySQL5.7下面,误操作导致的drop table db1.tb1; 的恢复方法:
MySQL5.7下面,误操作导致的drop table db1.tb1; 的恢复方法: 0.停业务数据写入.[iptables封禁] 1.从备份服务器上拉取最新的一个全备文件,恢复到一个临时的服务器上 ...
- MySQL 基于mysqldump备份工具实战演练
前言: 细节提示:先执行 show global variables like 'log_bin';看看log_bin的值,如果服务器变量log_bin的值为OFF,需要修改my.cnf配置文件,将l ...
- oracle数据库误操作把表删除了,怎样恢复
一:表的恢复 对误删的表,只要没有使用PURGE永久删除选项,那么从flash back区恢复回来希望是挺大的.一般步骤有:1.从flash back里查询被删除的表 select * from re ...
- 028:基于mysqldump备份脚本
MySQL Backup and Recovery 一 MySQL Backup 1.功能 mysqldump全量和增量备份,通过最近一次备份刷新产生binlog来定位执行增量. 脚本下载地址 git ...
- mysqldump 备份数据和恢复
命令行下具体用法如下: mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名; 一.导出数据: 导出整个数据库结构和数据mysqldump -h localhost -u ...
- 利用binlog server及Xtrabackup备份集来恢复误删表(drop)
Preface Today I'm gonna test how to rescue a dropped table from binlog server based on a ful ...
- 恢复被误操作删除的数据 fn_dblog
-- Script Name: Recover_Deleted_Data_Proc -- Script Type : Recovery Procedure -- Develop By: Muhamm ...
随机推荐
- 制作URL以GET方式提交的简单加密程序
首先我们用到的是 DESCryptoServiceProvider 类 对此微软给出的解释是 定义访问数据加密标准 (DES) 算法的加密服务提供程序 (CSP) 版本的包装对象.无法继承此类. 接下 ...
- 经典的hash函数
unsigned int SDBMHash(char *str){ unsigned int hash = 0; while (*str) { // equivale ...
- 【HDU4676】Sum Of Gcd(莫队+欧拉函数)
点此看题面 大致题意: 多组询问,求\(\sum_{i=L}^R\sum_{j=i+1}^Rgcd(i,j)\). 推式子 这道题我们可以考虑,每个因数\(d\)被统计答案的次数,肯定与其出现次数有关 ...
- Nodejs事件监听模块
nodejs里面是不存在浏览器里面都冒泡,捕获这些行为的,所以Nodejs实现了events这个模块,里面大多数的模块都集成了这个模块,所以events是node模块里面最重要都一个模块,他对外只暴露 ...
- maven parent version not found
需要把parent工程,也就是package是pom的那个工程先install一下 要是不行的话可以试下mvn -X clean install,-X表示强制从远程库更新dependency:再不行可 ...
- 运行时库例程-acc_get_num_devices
格式C 或 C++: int acc_get_num_devices( acc_device_t ); 描述例程 acc_get_num_devices 返回主机上指定类型的加速器设备数量.输入参数说 ...
- JavaEE权限管理系统的搭建(三)--------springmvc和mabatis整合环境搭建
本节介绍如何环境的搭建和配置: 首先要在父工程引入jar包依赖: <!-- 通过属性定义指定jar的版本 --> <properties> <spring.version ...
- 使用C#的新特性:可空类型
随着C#语言最新标准的出炉,现在它也提供了对可空类型的支持.这个小变化将会在处理那些包括可选项的数据库记录时非常有用.当然在其他地方,它也是非常有用的. 简单说来,可空数据类型就是包含了所定义的数据类 ...
- CSS-DOM
在所有的产品设计中,选择最适用的工具去解决问题是最基本的原则. ①使用(X)HTML去搭建文档的结构. ②使用CSS 去设置文档的呈现效果. ③使用DOM脚本去实现文档的行为. 文档中的每个元素都是一 ...
- C#获取包括一二级汉字的拼音 首字母
C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...