1. exec_time 到底表示什么时间?
MySQL binlog日志解析后,我们能看到会有 exec_time= ,从字面意思理解这个记录的是执行时间,那这个记录的到底是单条sql的执行时间?还是事务的执行时间?下面通过测试来解读一下!
2.创建测试库表
mysql> create database test_shao;
Query OK, 1 row affected (0.03 sec)
mysql> use test_shao;
Database changed
mysql> create table test_1(id int not null auto_increment,primary key(id)) engine=innodb default charset=utf8mb4;
Query OK, 0 rows affected (0.03 sec)
3.RC隔离级别下 事务测试
show variables like 'transaction_isolation';
+-----------------------+----------------+
| Variable_name | Value |
+-----------------------+----------------+
| transaction_isolation | READ-COMMITTED |
+-----------------------+----------------+
flush logs;
begin;
select count(*) from cmp_sys_1.message;
insert into test_1 select sleep(5);
select count(*) from cmp_sys_1.message;
insert into test_1 select sleep(10);
commit;
mysql> flush logs;
Query OK, 0 rows affected (0.02 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from cmp_sys_1.message;
+----------+
| count(*) |
+----------+
| 62882460 |
+----------+
1 row in set (45.24 sec)
mysql>
mysql> insert into test_1 select sleep(5);
Query OK, 1 row affected (5.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select count(*) from cmp_sys_1.message;
+----------+
| count(*) |
+----------+
| 62882460 |
+----------+
1 row in set (35.73 sec)
mysql> insert into test_1 select sleep(10);
Query OK, 1 row affected (10.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
4.解析第3步生成的主库binlog
show master status;
+-----------------+-----------+--------------+------------------+----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+-----------+--------------+------------------+----------------------------------------------+
| 3306-bin.000781 | 364155470 | | | bc129ea5-5f01-11ed-ae48-fa163efcbfd5:1-17199 |
+-----------------+-----------+--------------+------------------+----------------------------------------------+
show variables like 'log_bin_basename';
+------------------+-----------------------------------+
| Variable_name | Value |
+------------------+-----------------------------------+
| log_bin_basename | /app/mysql/mysql3306/log/3306-bin |
+------------------+-----------------------------------+
mysqlbinlog --base64-output=decode-rows -vvv 3306-bin.000781 >3306-bin.000781.txt
5.解析第3步生成的从库binlog