MySQL入门篇-MySQL 二进制日志binlog介绍

news2024/12/25 12:24:20

MySQl binlog介绍

binlog的作用

逻辑日志,记录的是数据库内部的所有变动(sql语句 行的改变)
server层日志,binlog不仅仅记录innodb的变动,也记录myisam存储引擎的变动。
innodb redo 是存储引擎层,和binlog不是一层,redo只记录innodb的变化。
binlog不记录 select show 等查询语句,记录dml ddl等数据库变动的语句.

可以查看mysql变更
mysql的复制架构(主从)
mysql备份恢复(可以通过binlog进行数据的补齐或者回滚)


binlog的位置

mysql> show variables like '%log_bin%';
+---------------------------------+-------------------------------------------------+
| Variable_name                   | Value                                           |
+---------------------------------+-------------------------------------------------+
| log_bin                         | ON                                              |
| log_bin_basename                | /usr/local/mysql/mysql-8.0/data/mysql-bin       |
| log_bin_index                   | /usr/local/mysql/mysql-8.0/data/mysql-bin.index |
| log_bin_trust_function_creators | OFF                                             |
| log_bin_use_v1_row_events       | OFF                                             |
| sql_log_bin                     | ON                                              |
+---------------------------------+-------------------------------------------------+
6 rows in set (0.00 sec)

log_bin为on代表开启了binlog
log_bin_basename的上一层是binog日志的位置/usr/local/mysql/mysql-8.0/data/mysql-bin

binlog相关参数

binlog格式 

binlog有三种格式statement,row以及mixed,默认使用默认使用statement,建议使用row格式

清理binlog 

reset master; //删除master的binlog,线上不要使用
purge master logs before ‘2012-03-30 17:20:00’; //删除指定日期以前的日志索引中binlog日志文件
purge master logs to ‘binlog.000002’; //删除指定日志文件的日志索引中binlog日志文件

如果想直接删除binlog
rm binlog.000002
(不要删除当前正在使用的binlog,也就是编号最大的binlog)
[root@namenode mysql3306]# cat mysql-bin.index 不会自动更新
/home/mysql3306/mysql3306/mysql-bin.000001
/home/mysql3306/mysql3306/mysql-bin.000002
主从复制如果删掉了,容易从库报错(保证从库不再同步该binlog的数据)

binlog和redo的区别

  • redo 物理逻辑日志 物理:数据页 逻辑: 数据页的改变
    binlog 是逻辑日志 记录的SQL或者是行改变
  • redo是innodb存储引擎层
    binlog是server层
  • redo时时刻刻都在写入文件
    binlog是 提交事务的写入(具体写入策略跟具体参数有关)

MySQl binlog恢复

语句级别的恢复

show master status;
flush logs;
show master status;
create table t2(id int,name varchar(100));
insert into t2 values (1,'a');
insert into t2 values (2,'b');
insert into t2 values (3,'c');
flush logs;
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000008 |      120 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.21 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000009 |      120 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> create table t2(id int,name varchar(100));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into t2 values (1,'a');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t2 values (2,'b');
Query OK, 1 row affected (0.00 sec)

mysql> insert into t2 values (3,'c');
Query OK, 1 row affected (0.00 sec)

mysql> select * from t2;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
|    2 | b    |
|    3 | c    |
+------+------+
3 rows in set (0.00 sec)

mysql> 
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)

通过mysqlbinlog查看 可以看到相关的sql语句都被打印出来

mysqlbinlog /u01/my3306/log/binlog/binlog.000009
[mysql@monitor binlog]$ mysqlbinlog /u01/my3306/log/binlog/binlog.000009
/*!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
#200816 21:55:18 server id 1  end_log_pos 120 CRC32 0x28e9c60f  Start: binlog v 4, server v 5.6.37-log created 200816 21:55:18
BINLOG '
xjo5Xw8BAAAAdAAAAHgAAAAAAAQANS42LjM3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAQ/G
6Sg=
'/*!*/;
# at 120
#200816 21:55:41 server id 1  end_log_pos 235 CRC32 0x98ce9bc5  Query   thread_id=1     exec_time=0     error_code=0
use `test`/*!*/;
SET TIMESTAMP=1597586141/*!*/;
SET @@session.pseudo_thread_id=1/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C gbk *//*!*/;
SET @@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table t2(id int,name varchar(100))
/*!*/;
# at 235
#200816 21:55:52 server id 1  end_log_pos 314 CRC32 0x3f15ad19  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586152/*!*/;
BEGIN
/*!*/;
# at 314
#200816 21:55:52 server id 1  end_log_pos 417 CRC32 0xfeaa465a  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586152/*!*/;
insert into t2 values (1,'a')
/*!*/;
# at 417
#200816 21:55:52 server id 1  end_log_pos 448 CRC32 0x55d2ec50  Xid = 45
COMMIT/*!*/;
# at 448
#200816 21:55:56 server id 1  end_log_pos 527 CRC32 0xe8ee6ecd  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586156/*!*/;
BEGIN
/*!*/;
# at 527
#200816 21:55:56 server id 1  end_log_pos 630 CRC32 0xf729214c  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586156/*!*/;
insert into t2 values (2,'b')
/*!*/;
# at 630
#200816 21:55:56 server id 1  end_log_pos 661 CRC32 0xa47e49c8  Xid = 46
COMMIT/*!*/;
# at 661
#200816 21:56:00 server id 1  end_log_pos 740 CRC32 0xac7fdd47  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586160/*!*/;
BEGIN
/*!*/;
# at 740
#200816 21:56:00 server id 1  end_log_pos 843 CRC32 0x7164118b  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586160/*!*/;
insert into t2 values (3,'c')
/*!*/;
# at 843
#200816 21:56:00 server id 1  end_log_pos 874 CRC32 0x777d6e18  Xid = 47
COMMIT/*!*/;
# at 874
#200816 21:56:12 server id 1  end_log_pos 918 CRC32 0x79221882  Rotate to binlog.000010  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*/;

通过–start-position、–stop-position限定时间段

mysqlbinlog --start-position=120 --stop-position=235  /u01/my3306/log/binlog/binlog.000009

测试记录:

[mysql@monitor binlog]$ mysqlbinlog --start-position=120 --stop-position=235  /u01/my3306/log/binlog/binlog.000009
/*!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
#200816 21:55:18 server id 1  end_log_pos 120 CRC32 0x28e9c60f  Start: binlog v 4, server v 5.6.37-log created 200816 21:55:18
BINLOG '
xjo5Xw8BAAAAdAAAAHgAAAAAAAQANS42LjM3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAQ/G
6Sg=
'/*!*/;
# at 120
#200816 21:55:41 server id 1  end_log_pos 235 CRC32 0x98ce9bc5  Query   thread_id=1     exec_time=0     error_code=0
use `test`/*!*/;
SET TIMESTAMP=1597586141/*!*/;
SET @@session.pseudo_thread_id=1/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C gbk *//*!*/;
SET @@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table t2(id int,name varchar(100))
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[mysql@monitor binlog]$ 

通过–start-datetime、–stop-datetime参数来指定时间段

mysqlbinlog --start-datetime='2020-08-16 21:55:41' --stop-datetime='2020-08-16 21:55:56'  /u01/my3306/log/binlog/binlog.000009
[mysql@monitor binlog]$ mysqlbinlog --start-datetime='2020-08-16 21:55:41' --stop-datetime='2020-08-16 21:55:56'  /u01/my3306/log/binlog/binlog.000009
/*!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
#200816 21:55:18 server id 1  end_log_pos 120 CRC32 0x28e9c60f  Start: binlog v 4, server v 5.6.37-log created 200816 21:55:18
BINLOG '
xjo5Xw8BAAAAdAAAAHgAAAAAAAQANS42LjM3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAQ/G
6Sg=
'/*!*/;
# at 120
#200816 21:55:41 server id 1  end_log_pos 235 CRC32 0x98ce9bc5  Query   thread_id=1     exec_time=0     error_code=0
use `test`/*!*/;
SET TIMESTAMP=1597586141/*!*/;
SET @@session.pseudo_thread_id=1/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C gbk *//*!*/;
SET @@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table t2(id int,name varchar(100))
/*!*/;
# at 235
#200816 21:55:52 server id 1  end_log_pos 314 CRC32 0x3f15ad19  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586152/*!*/;
BEGIN
/*!*/;
# at 314
#200816 21:55:52 server id 1  end_log_pos 417 CRC32 0xfeaa465a  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597586152/*!*/;
insert into t2 values (1,'a')
/*!*/;
# at 417
#200816 21:55:52 server id 1  end_log_pos 448 CRC32 0x55d2ec50  Xid = 45
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

另外,还有–database=ops指定只恢复ops数据库

Row格式的恢复

修改日志格式

mysql> show variables like '%binlog_format%';
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
1 row in set (0.00 sec)

mysql> set binlog_format = row;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%binlog_format%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+
1 row in set (0.00 sec)
-- 这个参数要为on,不然sql语句会被注释
mysql> show variables like 'binlog_rows_query_log_events';
+------------------------------+-------+
| Variable_name                | Value |
+------------------------------+-------+
| binlog_rows_query_log_events | ON    |
+------------------------------+-------+
1 row in set (0.00 sec)

测试sql

flush logs;
show master status;
create table t3(id int,name varchar(100));
insert into t3 values (1,'aaa');
insert into t3 values (2,'bbb');
insert into t3 values (3,'ccc');
update t3 set name='ddd' where id = 2;
select * from t3;
flush logs;

测试语句执行记录

mysql> flush logs;
Query OK, 0 rows affected (0.21 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |      120 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> create table t3(id int,name varchar(100));
Query OK, 0 rows affected (0.22 sec)

mysql> insert into t3 values (1,'aaa');
Query OK, 1 row affected (0.01 sec)

mysql> insert into t3 values (2,'bbb');
Query OK, 1 row affected (0.01 sec)

mysql> insert into t3 values (3,'ccc');
Query OK, 1 row affected (0.01 sec)

mysql> update t3 set name='ddd' where id = 2;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from t3;
+------+------+
| id   | name |
+------+------+
|    1 | aaa  |
|    2 | ddd  |
|    3 | ccc  |
+------+------+
3 rows in set (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.02 sec)

通过mysqlbinlog查看执行的日志

mysqlbinlog  --base64-output=DECODE-ROWS -v -v /u01/my3306/log/binlog/binlog.000011
[mysql@monitor binlog]$ mysqlbinlog  --base64-output=DECODE-ROWS -v -v /u01/my3306/log/binlog/binlog.000011
/*!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
#200816 22:30:45 server id 1  end_log_pos 120 CRC32 0xd552697f  Start: binlog v 4, server v 5.6.37-log created 200816 22:30:45
# at 120
#200816 22:32:39 server id 1  end_log_pos 235 CRC32 0x8cc6dae3  Query   thread_id=1     exec_time=0     error_code=0
use `test`/*!*/;
SET TIMESTAMP=1597588359/*!*/;
SET @@session.pseudo_thread_id=1/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C gbk *//*!*/;
SET @@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table t3(id int,name varchar(100))
/*!*/;
# at 235
#200816 22:32:49 server id 1  end_log_pos 307 CRC32 0x6e7bdf26  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597588369/*!*/;
BEGIN
/*!*/;
# at 307
#200816 22:32:49 server id 1  end_log_pos 362 CRC32 0xcfd834d7  Rows_query
# insert into t3 values (1,'aaa')
# at 362
#200816 22:32:49 server id 1  end_log_pos 410 CRC32 0xe0be9170  Table_map: `test`.`t3` mapped to number 74
# at 410
#200816 22:32:49 server id 1  end_log_pos 455 CRC32 0x2f857fed  Write_rows: table id 74 flags: STMT_END_F
### INSERT INTO `test`.`t3`
### SET
###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
###   @2='aaa' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
# at 455
#200816 22:32:49 server id 1  end_log_pos 486 CRC32 0xeb767c91  Xid = 56
COMMIT/*!*/;
# at 486
#200816 22:32:55 server id 1  end_log_pos 558 CRC32 0xc5a0a923  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597588375/*!*/;
BEGIN
/*!*/;
# at 558
#200816 22:32:55 server id 1  end_log_pos 613 CRC32 0x3c494320  Rows_query
# insert into t3 values (2,'bbb')
# at 613
#200816 22:32:55 server id 1  end_log_pos 661 CRC32 0x0767f99b  Table_map: `test`.`t3` mapped to number 74
# at 661
#200816 22:32:55 server id 1  end_log_pos 706 CRC32 0x0f7eb2a7  Write_rows: table id 74 flags: STMT_END_F
### INSERT INTO `test`.`t3`
### SET
###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
###   @2='bbb' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
# at 706
#200816 22:32:55 server id 1  end_log_pos 737 CRC32 0x4382e7c6  Xid = 57
COMMIT/*!*/;
# at 737
#200816 22:33:00 server id 1  end_log_pos 809 CRC32 0x1a477c11  Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597588380/*!*/;
BEGIN
/*!*/;
# at 809
#200816 22:33:00 server id 1  end_log_pos 864 CRC32 0x4045e1c3  Rows_query
# insert into t3 values (3,'ccc')
# at 864
#200816 22:33:00 server id 1  end_log_pos 912 CRC32 0xfa37dcf1  Table_map: `test`.`t3` mapped to number 74
# at 912
#200816 22:33:00 server id 1  end_log_pos 957 CRC32 0x9e5fd360  Write_rows: table id 74 flags: STMT_END_F
### INSERT INTO `test`.`t3`
### SET
###   @1=3 /* INT meta=0 nullable=1 is_null=0 */
###   @2='ccc' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
# at 957
#200816 22:33:00 server id 1  end_log_pos 988 CRC32 0x7da1f606  Xid = 58
COMMIT/*!*/;
# at 988
#200816 22:35:03 server id 1  end_log_pos 1060 CRC32 0x1d91e750         Query   thread_id=1     exec_time=0     error_code=0
SET TIMESTAMP=1597588503/*!*/;
BEGIN
/*!*/;
# at 1060
#200816 22:35:03 server id 1  end_log_pos 1121 CRC32 0x99eddaa3         Rows_query
# update t3 set name='ddd' where id = 2
# at 1121
#200816 22:35:03 server id 1  end_log_pos 1169 CRC32 0x7581ae12         Table_map: `test`.`t3` mapped to number 74
# at 1169
#200816 22:35:03 server id 1  end_log_pos 1225 CRC32 0x8573abd1         Update_rows: table id 74 flags: STMT_END_F
### UPDATE `test`.`t3`
### WHERE
###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
###   @2='bbb' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
### SET
###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
###   @2='ddd' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
# at 1225
#200816 22:35:03 server id 1  end_log_pos 1256 CRC32 0x49e1eb6b         Xid = 59
COMMIT/*!*/;
# at 1256
#200816 22:35:19 server id 1  end_log_pos 1300 CRC32 0x1febd0af         Rotate to binlog.000012  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*/;

测试一下恢复

-- drop表
drop table t3;
-- 通过mysqlbinlog进行恢复
mysqlbinlog  --base64-output=DECODE-ROWS -v -v /u01/my3306/log/binlog/binlog.000011 | mysql -uroot -pabc123 -v
-- 查看得知,建表语句是恢复了,但是dml没有恢复,应该是sql语句被注释了的原因
[mysql@monitor binlog]$ mysqlbinlog  --base64-output=DECODE-ROWS -v -v /u01/my3306/log/binlog/binlog.000011 | mysql -uroot -pabc123 -v
Warning: Using a password on the command line interface can be insecure.
--------------
/*!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*/
--------------

--------------
SET TIMESTAMP=1597588359
--------------

--------------
SET @@session.pseudo_thread_id=1
--------------

--------------
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1
--------------

--------------
SET @@session.sql_mode=1075838976
--------------

--------------
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1
--------------

--------------
/*!*/
--------------

--------------
SET @@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=33
--------------

--------------
SET @@session.lc_time_names=0
--------------

--------------
SET @@session.collation_database=DEFAULT
--------------

--------------
create table t3(id int,name varchar(100))
--------------

--------------
SET TIMESTAMP=1597588369
--------------

--------------
BEGIN
--------------

--------------
COMMIT
--------------

--------------
SET TIMESTAMP=1597588375
--------------

--------------
BEGIN
--------------

--------------
COMMIT
--------------

--------------
SET TIMESTAMP=1597588380
--------------

--------------
BEGIN
--------------

--------------
COMMIT
--------------

--------------
SET TIMESTAMP=1597588503
--------------

--------------
BEGIN
--------------

--------------
COMMIT
--------------

--------------
ROLLBACK
--------------

--------------
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/
--------------

--------------
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/
--------------

其实对于恢复而言,直接执行即可,不用查看到具体的sql语句

-- mysqlbinlog后面可以带多个binlog文件
mysqlbinlog /u01/my3306/log/binlog/binlog.000011 | mysql -uroot -p
[mysql@monitor binlog]$ mysqlbinlog /u01/my3306/log/binlog/binlog.000011 | mysql -uroot -p
Enter password: 
[mysql@monitor binlog]$ 

mysql> select * from t3;
+------+------+
| id   | name |
+------+------+
|    1 | aaa  |
|    2 | ddd  |
|    3 | ccc  |
+------+------+
3 rows in set (0.00 sec)

参考

MySQL 二进制日志binlog介绍_只是甲的博客-CSDN博客_mysqlbinog -v输出介绍 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/341893.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

spark02-内存数据分区切分原理

代码:val conf: SparkConf new SparkConf().setMaster("local[*]").setAppName("wordcount") val scnew SparkContext(conf) //[1] [2,3] [4,5] val rdd: RDD[Int] sc.makeRDD(List(1,2,3,4,5),3) //将处理的数据保存分区文件 rdd.saveAsText…

【PTA Advanced】1152 Google Recruitment(C++)

目录 题目 Input Specification: Output Specification: Sample Input 1: Sample Output 1: Sample Input 2: Sample Output 2: 思路 代码 题目 In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below)…

清除 git 所有历史提交记录,使其为新库

清除 git 所有历史提交记录,使其为新库需求方案需求 基于以前的仓库重新开发,这样可保留以前的配置等文件,但是需要删除全部的历史记录、tag、分支等。 方案 创建新的分支 使用 --orphan 选项,可创建1个干净的分支(无…

设置测试用例的具体方法

文章目录一、等价类分区/分块的概念等价类的划分二、边界值三、因果图(判定表)四、场景设计法五、错误猜测法总结一、等价类 用户的密码为6~18位,测试的时候使用到的测试数据是什么? 穷举法,6,7,8,9,10…18全部都测试一边,可以 但是将范围改成6~1000位,穷举法就不可取了 分区/…

从零实现高并发WebRTC服务器(五):ICE协议

文章目录零、ICE具体做些什么一、ICE协议是什么二、ICE Candidate2.1 ICE CANDIDATE TYPE2.2 收集candidate零、ICE具体做些什么 收集candidate对不同type的所有candidate pair进行排序,比如优先使用同一内网的host candidate连通性检查 一、ICE协议是什么 ICE,i…

线性杂双功能PEG试剂OPSS-PEG-Acid,OPSS-PEG-COOH,巯基吡啶聚乙二醇羧基

英文名称:OPSS-PEG-COOH,OPSS-PEG-Acid 中文名称:巯基吡啶-聚乙二醇-羧基 OPSS-PEG-COOH是一种具有OPSS和羧基的线性杂双功能PEG试剂。它是一种有用的带有PEG间隔基的交联剂。OPSS代表正吡啶基二硫化物或邻吡啶基二硫代,与硫醇、…

Java 修饰符和运算符,超详细整理,适合新手入门

目录 一、访问控制修饰符 1、访问权限 二、运算符 1、算术运算符 2、关系运算符 3、逻辑运算符 4、赋值运算符 5、三元运算符 一、访问控制修饰符 Java 支持 4 种不同的访问权限: private 私有的 protected 受保护的 public 公共的 default 默认 1、…

程序员必备小众又实用的网站,你知道几个?

程序员是世人眼中的高薪职业,虽然亚历山大,但是年收入非常可观。 职场上的程序员有很多所谓的标签, 比如:秃头,找不到女朋友,和产品经理的斗智斗勇等等.... 可以说,一个程序员的必备素养就是…

【C++11智能指针】unique_ptr

【C11智能指针】unique_ptr 概述 一个 unique_ptr “拥有”它所指向的对象。 与 shared_ptr 不同&#xff0c;某个时刻只能有一个 unique_ptr 指向一个给定对象。 当 unique_ptr 被销毁时&#xff0c;它所指向的对象也被销毁。 初始化 直接初始化 unique_ptr<int> p…

AcWing 166. 数独(DFS + 剪枝优化 + lowbit函数 + 状态压缩)

AcWing 166. 数独&#xff08;DFS 剪枝优化 lowbit函数 状态压缩&#xff09;一、题目二、分析1、状态压缩2、lowbit函数&#xff08;1&#xff09;函数作用&#xff08;2&#xff09;函数实现3、DFS思路4、剪枝优化三、代码一、题目 二、分析 1、状态压缩 那么如果针对某一…

情人节专场即将到来,各大平台各显神通

一年一度的情人节即将到来&#xff0c;情人节除了有情侣、恋人之间表达爱意或者追求浪漫之外&#xff0c;也有很多人想要购买一些特殊的礼物送给自己的爱人或者亲人。对于跨境电商而言&#xff0c;这个时段往往能更好的将品牌与社交媒体上的目标客户建立起联系&#xff0c;同时…

【青训营】分布式定时任务简述

这是我参与「第五届青训营 」伴学笔记创作活动的第 13 天 分布式定时任务简述 定义 定时任务是指系统为了自动完成特定任务&#xff0c;实时、延时、周期性完成任务调度的过程。分布式定时任务是把分散的、可靠性差的定时任务纳入统一平台&#xff0c;并且实现集群管理调度和…

OpenCV-PyQT项目实战(6)项目案例02滚动条应用

欢迎关注『OpenCV-PyQT项目实战 Youcans』系列&#xff0c;持续更新中 OpenCV-PyQT项目实战&#xff08;1&#xff09;安装与环境配置 OpenCV-PyQT项目实战&#xff08;2&#xff09;QtDesigner 和 PyUIC 快速入门 OpenCV-PyQT项目实战&#xff08;3&#xff09;信号与槽机制 …

JumpServer开源堡垒机v3.0版本设计重点解读

编者注&#xff1a;在1月17日的JumpServer开源堡垒机v3.0预发布恳谈会直播中&#xff0c;JumpServer创始人广宏伟与大家分享了JumpServer v3.0版本的设计思路与功能亮点。在v3.0版本正式发布之前&#xff0c;JumpServer开源项目组基于此次直播内容为大家整理总结了JumpServer v…

C++11可变模板参数

C11可变模板参数一、简介二、语法三、可变模版参数函数3.1、递归函数方式展开参数包3.2、逗号表达式展开参数包一、简介 C11的新特性–可变模版参数&#xff08;variadic templates&#xff09;是C11新增的最强大的特性之一&#xff0c;它对参数进行了高度泛化&#xff0c;它能…

STM32单片机红外遥控

红外遥控接口电路STM32单片机红外遥控程序源代码#include "sys.h"#define LED_RED PBout(12) //红色发光二极管控制管脚初始化PB12#define LED_GREEN PBout(13) //绿色发光二极管控制管脚初始化PB13#define LED_YELLOW PBout(14) //黄色发光二极管控制管脚初始化PB14…

反射,枚举,lambda表达式

目录 1、反射 1.1 基本概念 1.2 反射相关的类 1.3 创建 Class 对象 1.4 反射的使用 1.4.1 通过反射创建对象&#xff1a; 1.4.2 获取私有的构造方法 1.4.3 获取私有的成员变量 1.4.4 获取私有的方法 1.5 总结 2、枚举 2.1 认识枚举 2.2 使用枚举 2.3 枚举与反射…

第4章 流程控制-if-else,Switch,For循环(循环守卫,循环步长,倒叙打印),While循环,多重循环...

第 4 章 流程控制-if-else,Switch,For循环(循环守卫&#xff0c;循环步长&#xff0c;倒叙打印)&#xff0c;While循环&#xff0c;多重循环 4.1 分支控制 if-else 让程序有选择的的执行&#xff0c;分支控制有三种&#xff1a;单分支、双分支、多分支 4.1.1 单分支 1)基本语法…

Leetcode-每日一题1234. 替换子串得到平衡字符串(滑动窗口 + 哈希表)

题目链接&#xff1a;https://leetcode.cn/problems/replace-the-substring-for-balanced-string/description/ 思路 题目意思 这题意思是一个只含有[Q, W, E, R] 四个字符的字符串s且长度一定是 4的倍数&#xff0c; 需要你通过替换子串&#xff0c;使他变成一个「平衡字符…

【C++设计模式】学习笔记(6):Bridge 桥模式

目录 简介动机(Motivation)模式定义结构(Structure)要点总结笔记结语简介 Hello! 非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出~ ଘ(੭ˊᵕˋ)੭ 昵称:海轰 标签:程序猿|C++选手|学生 简介:因C语言结识编程,随后转入计算机专业,获得过国家奖学金…