[root@test ~]# systemctl stop mysql [root@test ~]# vim /etc/my.cnf [mysqld] log_bin = mysql_bin # 加入此项 [root@test ~]# systemctl start mysql [root@test ~]# mysql mysql> SHOW GLOBAL VARIABLES LIKE 'sql_log_bin'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | sql_log_bin | ON | +---------------+-------+ # 如果此项为ON,表示开启了二进制日志 mysql> SHOW BINARY LOGS; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql_bin.000001 | 120 | +------------------+-----------+
[[root@test ~]# mysqlbinlog /var/lib/mysql/mysql_bin.000001 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #190104 15:41:52 server id 1 end_log_pos 120 CRC32 0x2b1c1f39 Start: binlog v 4, server v 5.6.42-log created 190104 15:41:52 at startup ROLLBACK/*!*/; BINLOG ' QA4vXA8BAAAAdAAAAHgAAAAAAAQANS42LjQyLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAABADi9cEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAATkf HCs= '/*!*/; # at 120 #190104 15:52:41 server id 1 end_log_pos 167 CRC32 0x7f00ec56 Rotate to mysql_bin.000002 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; # /var/lib/mysql是数据库的路径
[root@test ~]# mysqlbinlog --start-position=120 --stop-position=167 /var/lib/mysql/mysql_bin.000001 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #190104 15:41:52 server id 1 end_log_pos 120 CRC32 0x2b1c1f39 Start: binlog v 4, server v 5.6.42-log created 190104 15:41:52 at startup ROLLBACK/*!*/; BINLOG ' QA4vXA8BAAAAdAAAAHgAAAAAAAQANS42LjQyLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAABADi9cEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAATkf HCs= '/*!*/; # at 120 #190104 15:52:41 server id 1 end_log_pos 167 CRC32 0x7f00ec56 Rotate to mysql_bin.000002 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; # 查看位置從120到167 [root@test ~]# mysqlbinlog --start-datetime='2019-01-04 15:41:52' /var/lib/mysql/mysql_bin.000001 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #190104 15:41:52 server id 1 end_log_pos 120 CRC32 0x2b1c1f39 Start: binlog v 4, server v 5.6.42-log created 190104 15:41:52 at startup ROLLBACK/*!*/; BINLOG ' QA4vXA8BAAAAdAAAAHgAAAAAAAQANS42LjQyLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAABADi9cEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAATkf HCs= '/*!*/; # at 120 #190104 15:52:41 server id 1 end_log_pos 167 CRC32 0x7f00ec56 Rotate to mysql_bin.000002 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; # 命令中的日期一定要使用****-**-**这样的格式,不然会报错:"Incorrect date and time argument",日期和时间参数不正确。