全备之后误删一个表恢复到现在时间点
作者:互联网
[root@mysql8-31 mysql]# mysqldump --help [root@mysql8-31 mysql]# mysqldump -uroot -A --source-data=2 > /backup/all.sql #默认就是1,主从 CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000008', MASTER_LOG_POS=156; #从这个点之后找数据 mysql> select * from teachers; +-----+---------------+-----+--------+ | TID | Name | Age | Gender | +-----+---------------+-----+--------+ | 1 | Song Jiang | 45 | M | | 2 | Zhang Sanfeng | 94 | M | | 3 | Miejue Shitai | 77 | F | | 4 | Lin Chaoying | 93 | F | +-----+---------------+-----+--------+ 4 rows in set (0.00 sec) mysql> insert teachers (name,age)values('a','22'); Query OK, 1 row affected (0.01 sec) mysql> insert teachers (name,age)values('b','23'); Query OK, 1 row affected (0.00 sec) #误删除 mysql> drop table teachers; 再新增数据 mysql> insert students (name,age)values('c','22'); Query OK, 1 row affected (0.00 sec) mysql> insert students (name,age)values('d','22'); Query OK, 1 row affected (0.01 sec) mysql> select * from students; | 28 | c | 22 | F | NULL | NULL | | 29 | d | 22 | F | NULL | NULL | +-------+---------------+-----+--------+---------+-----------+ 29 rows in set (0.01 sec) 暂停访问 [root@mysql8-31 backup]# head all.sql -n30 -- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000008', MASTER_LOG_POS=156; mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000008 | 1568 | | | | +------------------+----------+--------------+------------------+-------------------+ 生成全备之后二进制文件 [root@mysql8-31 logbin]# mysqlbinlog --start-position=156 /data/mysql/logbin/mysql-bin.000008 > /backup/logbin.sql [root@mysql8-31 backup]# grep -in drop logbin.sql 90:DROP TABLE `teachers` /* generated by server */ vim logbin.sql +90 [root@mysql8-31 backup]# sed -n '/^DROP TABLE `teachers`'/p logbin.sql DROP TABLE `teachers` /* generated by server */ [root@mysql8-31 backup]# sed -i '/^DROP TABLE `teachers`/d' logbin.sql 还原验证 ERROR 1790 (HY000): @@SESSION.GTID_NEXT cannot be changed by a client that owns a GTID. The client owns ANONYMOUS. Ownership is released on COMMIT or ROLLBACK. # at 827 #220517 22:11:46 server id 8 end_log_pos 966 CRC32 0x750c2e07 Query thread_id=12 exec_time=0 error_code=0 Xid = 1465 use `hellodb`/*!*/; SET TIMESTAMP=1652796706/*!*/; DROP ** /*!*/; 全删 90行 drop 命令及往上 ERROR 1790 (HY000) at line 94: @@SESSION.GTID_NEXT cannot be changed by a client that owns a GTID. The client owns ANONYMOUS. Ownership is released on COMMIT or ROLLBACK. mysql> select @@log_bin; +-----------+ | @@log_bin | +-----------+ | 1 | +-----------+ 临时关闭 mysql < all.sql mysql < logbin.sql
标签:logbin,mysql8,恢复,31,sql,误删,teachers,mysql,全备 来源: https://www.cnblogs.com/gxc888/p/16282774.html