load data語句如何保證主備複製資料一致性(一)
-
背景
-
機器配置
* CPU:16 vcpus
* 磁碟:100G flash卡 data&binlog混用
* 記憶體:64G - 資料庫版本:MySQL 5.7.18
-
資料庫IP資訊:主庫IP 10.10.30.241,從庫IP 10.10.30.250
-
資料庫引數配置:
* 主庫:雙一,log_slave_updates,log-bin,secure_file_priv='',server-id=3306241,binlog_rows_query_log_events=ON,sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
* 從庫:雙一,log_slave_updates,log-bin,binlog_rows_query_log_events=ON,server-id=3306250,sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' -
測試目的:透過示例演示並檢視過程中binlog中如何記錄load data語句等方式來驗證 load data語句如何保證主備複製資料一致性
* 將分別在四種隔離級別下(會話級別修改tx_isolation)針對binlog_format(會話級別修改binlog_format)的三種格式分別進行演示執行load data語句,觀察MySQL server層如何處理,主庫binlog中如何記錄load data語句,備庫的binlog中如何如何記錄load data語句
* 本文假定你已經搭建好了主備複製環境,如果未搭建請先自行搭建主備複製環境 -
PS:本文僅針對測試目的做驗證演示,關於binlog_format三種格式以及事務的四種隔離級別詳細說明請查閱相關資料,本文不做解讀
* binlog_format參考資料:https://dev.mysql.com/doc/refman/5.7/en/replication-formats.html
* 事務隔離級別參考資料:https://dev.mysql.com/doc/refman/5.7/en/innodb-transaction-isolation-levels.html
-
機器配置
1、製造測試資料
- 建庫
- admin@localhost : (none) 07:34:39> create database if not exists xiaoboluo;
- Query OK, 1 row affected (0.00 sec)
- 建表
- admin@localhost : (none) 10:04:52> use xiaoboluo
- Database changed
- admin@localhost : xiaoboluo 10:04:57> create table if not exists test_load(id int unsigned not null primary key auto_increment,test varchar(100));
- Query OK, 0 rows affected (0.01 sec)
- 插入測試資料
- admin@localhost : xiaoboluo 10:05:32> insert into test_load(test) values('1'),('2'),('null'),('4');
- Query OK, 4 rows affected (0.01 sec)
- Records: 4 Duplicates: 0 Warnings: 0
- admin@localhost : xiaoboluo 10:06:01> select * from test_load;
- +----+------+
- | id | test |
- +----+------+
- | 2 | 1 |
- | 4 | 2 |
- | 6 | null |
- | 8 | 4 |
- +----+------+
- 4 rows in set (0.00 sec)
- 執行select …into outifile語句生成load data需要的資料文字檔案
- admin@localhost : xiaoboluo 10:12:41> select * from test_load into outfile "/tmp/test_load.txt";
- Query OK, 4 rows affected (0.01 sec)
- admin@localhost : xiaoboluo 10:12:42> system cat /tmp/test_load.txt;
- 2 1
- 4 2
- 6 null
- 8 4
2、read-uncommitted隔離級別
2.1. binlog_format=statement
- 先在主庫中把binlog_format修改為statement,隔離級別修改為read-uncommitted,並重新整理主從庫binlog
- # 主庫
- admin@localhost : xiaoboluo 09:37:09> set binlog_format=statement;
- Query OK, 0 rows affected (0.00 sec)
- admin@localhost : xiaoboluo 09:39:24> set tx_isolation='read-uncommitted';
- Query OK, 0 rows affected (0.00 sec)
- admin@localhost : xiaoboluo 09:39:44> flush binary logs;
- Query OK, 0 rows affected (0.01 sec)
- # 從庫
- mysql> flush binary logs;
- Query OK, 0 rows affected (0.01 sec)
- mysql>
- 主庫清空表test_load並執行load data語句
- admin@localhost : xiaoboluo 09:39:54> truncate test_load;
- Query OK, 0 rows affected (0.00 sec)
- admin@localhost : xiaoboluo 09:41:13> load data infile '/tmp/test_load.txt' into table test_load;
- ERROR 1665 (HY000): Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
- Error (Code 1665): Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
- Error (Code 1015): Can
- 從以上結果中可以看到,在RU隔離級別下,binlog_format設定為statement不允許load data語句執行,從報錯資訊上可以看到,在RC和RU隔離級別下,binlog只能以row格式記錄,所以statement無法記錄binlog
- 檢視主庫表test_load中的資料
- admin@localhost : xiaoboluo 09:41:52> select * from test_load;
- Empty set (0.00 sec)
- 從以上結果中可以看到,表資料並沒有匯入成功,現在解析binlog檢視一下
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# ll
- total 196
- -rw-r----- 1 mysql mysql 4916 May 4 00:11 mysql-bin.000014
- -rw-r----- 1 mysql mysql 4557 May 4 00:12 mysql-bin.000015
- -rw-r----- 1 mysql mysql 5595 May 4 09:39 mysql-bin.000016
- -rw-r----- 1 mysql mysql 366 May 4 09:41 mysql-bin.000017
- -rw-r----- 1 mysql mysql 884 May 4 09:39 mysql-bin.index
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# mysqlbinlog -vvv --base64-output=decode-rows mysql-bin.000017
- ......
- use `xiaoboluo`/*!*/;
- ......
- truncate test_load
- /*!*/;
- SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
- DELIMITER ;
- # End of log file
- ......
- 從上面的結果中可以看到,解析binlog的結果中除了use db和truncate table語句之外,沒有其他的操作了,說明並沒有資料寫入,load data語句被mysql server直接拒絕執行了
2.2. binlog_format=mixed
- 先在主庫中把binlog_format修改為mixed,隔離級別不要動,並重新整理主從庫binlog
- # 主庫
- admin@localhost : xiaoboluo 09:44:05> set binlog_format=mixed;
- Query OK, 0 rows affected (0.00 sec)
- admin@localhost : xiaoboluo 09:49:49> flush binary logs;
- Query OK, 0 rows affected (0.01 sec)
- # 從庫
- mysql> flush binary logs;
- Query OK, 0 rows affected (0.01 sec)
- mysql>
- 主庫清空表test_load並執行load data語句
- admin@localhost : xiaoboluo 09:49:57> truncate test_load;
- Query OK, 0 rows affected (0.01 sec)
- admin@localhost : xiaoboluo 09:51:12> load data infile '/tmp/test_load.txt' into table test_load;
- Query OK, 4 rows affected (0.00 sec)
- Records: 4 Deleted: 0 Skipped: 0 Warnings: 0
- 從以上結果中可以看到,在RU隔離級別下,binlog_format設定為mixed允許load data語句執行
- 檢視主庫表test_load中的資料
- admin@localhost : xiaoboluo 09:51:24> select * from test_load;
- +----+------+
- | id | test |
- +----+------+
- | 2 | 1 |
- | 4 | 2 |
- | 6 | null |
- | 8 | 4 |
- +----+------+
- 4 rows in set (0.00 sec)
- 從以上結果中可以看到,表資料匯入成功,現在解析binlog檢視一下
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# ll
- total 196
- -rw-r----- 1 mysql mysql 4916 May 4 00:11 mysql-bin.000014
- -rw-r----- 1 mysql mysql 4557 May 4 00:12 mysql-bin.000015
- -rw-r----- 1 mysql mysql 5595 May 4 09:39 mysql-bin.000016
- -rw-r----- 1 mysql mysql 366 May 4 09:41 mysql-bin.000017
- -rw-r----- 1 mysql mysql 744 May 4 09:51 mysql-bin.000018
- -rw-r----- 1 mysql mysql 936 May 4 09:49 mysql-bin.index
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# mysqlbinlog -vv --base64-output=decode-rows mysql-bin.000018
- # at 259
- #170504 9:51:12 server id 3306241 end_log_pos 354 CRC32 0xff83f0ce Query thread_id=155 exec_time=0 error_code=0
- use `xiaoboluo`/*!*/;
- ......
- truncate test_load
- ......
- BEGIN
- /*!*/;
- # at 501
- #170504 9:51:24 server id 3306241 end_log_pos 583 CRC32 0xfef1767a Rows_query
- # load data infile '/tmp/test_load.txt' into table test_load # 這裡可以看到load data語句在這裡,這裡是開啟了引數binlog_rows_query_log_events=ON之後記錄的原生sql,預設被加了註釋,主備複製不會執行
- # at 583
- #170504 9:51:24 server id 3306241 end_log_pos 643 CRC32 0x349b62a4 Table_map: `xiaoboluo`.`test_load` mapped to number 340
- # at 643
- #170504 9:51:24 server id 3306241 end_log_pos 713 CRC32 0x4ceacc10 Write_rows: table id 340 flags: STMT_END_F
- ### INSERT INTO `xiaoboluo`.`test_load` #這裡是用於主備複製的資料變更日誌,可以看到在mixed格式下被轉換為了row格式
- ### SET
- ### @1=2 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='1' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=4 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='2' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=6 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='null' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=8 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='4' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- # at 713
- #170504 9:51:24 server id 3306241 end_log_pos 744 CRC32 0xfa76965b Xid = 1237
- COMMIT/*!*/;
- 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*/
-
從上面解析binlog的結果中可以看到,資料寫入成功,load data語句被轉換為row格式記錄在binlog中
-
檢視備庫中資料是否正確複製
- mysql> use xiaoboluo
- 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
- mysql> select * from test_load;
- +----+------+
- | id | test |
- +----+------+
- | 2 | 1 |
- | 4 | 2 |
- | 6 | null |
- | 8 | 4 |
- +----+------+
- 4 rows in set (0.00 sec)
- 解析備庫binlog中是如何記錄的load data語句
- [root@e710d318-d5b4-4bc7-a606-d09f06ff5f5d binlog]# ll
- total 100
- -rw-r----- 1 mysql mysql 990 May 1 01:36 mysql-bin.000001
- -rw-r----- 1 mysql mysql 54766 May 4 00:02 mysql-bin.000002
- -rw-r----- 1 mysql mysql 21376 May 4 09:40 mysql-bin.000003
- -rw-r----- 1 mysql mysql 401 May 4 09:50 mysql-bin.000004
- -rw-r----- 1 mysql mysql 730 May 4 09:51 mysql-bin.000005
- -rw-r----- 1 mysql mysql 260 May 4 09:50 mysql-bin.index
- [root@e710d318-d5b4-4bc7-a606-d09f06ff5f5d binlog]# mysqlbinlog -vv --base64-output=decode-rows mysql-bin.000005
- ...
- #170504 9:51:12 server id 3306241 end_log_pos 354 CRC32 0xff83f0ce Query thread_id=155 exec_time=0 error_code=0
- use `xiaoboluo`/*!*/;
- ...
- truncate test_load
- ...
- BEGIN
- /*!*/;
- # at 487
- #170504 9:51:24 server id 3306241 end_log_pos 569 CRC32 0x67a31998 Rows_query
- # load data infile '/tmp/test_load.txt' into table test_load # 這裡可以看到load data語句在這裡,這裡是開啟了引數binlog_rows_query_log_events=ON之後記錄的原生sql,預設被加了註釋,主備複製不會執行
- # at 569
- #170504 9:51:24 server id 3306241 end_log_pos 629 CRC32 0x6420d19b Table_map: `xiaoboluo`.`test_load` mapped to number 301
- # at 629
- #170504 9:51:24 server id 3306241 end_log_pos 699 CRC32 0xf5fff0d8 Write_rows: table id 301 flags: STMT_END_F
- ### INSERT INTO `xiaoboluo`.`test_load` #這裡是備庫記錄的主庫binlog日誌,可以看到在mixed格式下被轉換為了row格式
- ### SET
- ### @1=2 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='1' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=4 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='2' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=6 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='null' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=8 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='4' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- # at 699
- #170504 9:51:24 server id 3306241 end_log_pos 730 CRC32 0xd5a3bda4 Xid = 424
- COMMIT/*!*/;
- ...
2.3. binlog_format=row
- 先在主庫中把binlog_format修改為row,隔離級別不要動,並重新整理主從庫binlog
- # 主庫
- admin@localhost : xiaoboluo 11:05:20> set binlog_format=row;
- Query OK, 0 rows affected (0.00 sec)
- admin@localhost : xiaoboluo 11:18:23> flush binary logs;
- Query OK, 0 rows affected (0.01 sec)
- # 從庫
- mysql> flush binary logs;
- Query OK, 0 rows affected (0.01 sec)
- mysql>
- 主庫清空表test_load並執行load data語句
- admin@localhost : xiaoboluo 11:18:26> truncate test_load;
- Query OK, 0 rows affected (0.01 sec)
- admin@localhost : xiaoboluo 11:18:51> load data infile '/tmp/test_load.txt' into table test_load;
- Query OK, 4 rows affected (0.00 sec)
- Records: 4 Deleted: 0 Skipped: 0 Warnings: 0
- 從以上結果中可以看到,在RU隔離級別下,binlog_format設定為row允許load data語句執行
- 檢視主庫表test_load中的資料
- admin@localhost : xiaoboluo 11:18:57> select * from test_load;
- +----+------+
- | id | test |
- +----+------+
- | 2 | 1 |
- | 4 | 2 |
- | 6 | null |
- | 8 | 4 |
- +----+------+
- 4 rows in set (0.00 sec)
- 從以上結果中可以看到,表資料匯入成功,現在解析binlog檢視一下
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# ll
- total 196
- -rw-r----- 1 mysql mysql 4916 May 4 00:11 mysql-bin.000014
- -rw-r----- 1 mysql mysql 4557 May 4 00:12 mysql-bin.000015
- -rw-r----- 1 mysql mysql 5595 May 4 09:39 mysql-bin.000016
- -rw-r----- 1 mysql mysql 366 May 4 09:41 mysql-bin.000017
- -rw-r----- 1 mysql mysql 744 May 4 09:51 mysql-bin.000018
- -rw-r----- 1 mysql mysql 744 May 4 11:18 mysql-bin.000019
- -rw-r----- 1 mysql mysql 988 May 4 11:18 mysql-bin.index
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# mysqlbinlog -vv --base64-output=decode-rows mysql-bin.000018
- # at 259
- #170504 11:18:51 server id 3306241 end_log_pos 354 CRC32 0x9d5985ad Query thread_id=155 exec_time=0 error_code=0
- use `xiaoboluo`/*!*/;
- ......
- truncate test_load
- ......
- BEGIN
- /*!*/;
- # at 501
- #170504 11:18:57 server id 3306241 end_log_pos 583 CRC32 0x0e8f7603 Rows_query
- # load data infile '/tmp/test_load.txt' into table test_load # 這裡可以看到load data語句在這裡,這裡是開啟了引數binlog_rows_query_log_events=ON之後記錄的原生sql,預設被加了註釋,主備複製不會執行
- # at 583
- #170504 11:18:57 server id 3306241 end_log_pos 643 CRC32 0xe1c5d4d0 Table_map: `xiaoboluo`.`test_load` mapped to number 341
- # at 643
- #170504 11:18:57 server id 3306241 end_log_pos 713 CRC32 0x31619df3 Write_rows: table id 341 flags: STMT_END_F
- ### INSERT INTO `xiaoboluo`.`test_load` #這裡是用於主備複製的資料變更日誌,可以看到在row格式下被轉換為了row格式
- ### SET
- ### @1=2 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='1' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=4 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='2' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=6 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='null' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=8 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='4' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- # at 713
- #170504 11:18:57 server id 3306241 end_log_pos 744 CRC32 0x18b14b52 Xid = 1245
- COMMIT/*!*/;
- ......
-
從上面解析binlog的結果中可以看到,資料寫入成功,load data語句被轉換為row格式記錄在binlog中
-
檢視備庫中資料是否正確複製
- mysql> use xiaoboluo
- Database changed
- mysql> select * from test_load;
- +----+------+
- | id | test |
- +----+------+
- | 2 | 1 |
- | 4 | 2 |
- | 6 | null |
- | 8 | 4 |
- +----+------+
- 4 rows in set (0.00 sec)
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# ll
- total 196
- -rw-r----- 1 mysql mysql 4916 May 4 00:11 mysql-bin.000014
- -rw-r----- 1 mysql mysql 4557 May 4 00:12 mysql-bin.000015
- -rw-r----- 1 mysql mysql 5595 May 4 09:39 mysql-bin.000016
- -rw-r----- 1 mysql mysql 366 May 4 09:41 mysql-bin.000017
- -rw-r----- 1 mysql mysql 744 May 4 09:51 mysql-bin.000018
- -rw-r----- 1 mysql mysql 744 May 4 11:18 mysql-bin.000019
- -rw-r----- 1 mysql mysql 988 May 4 11:18 mysql-bin.index
- [root@5f1772e3-0c7a-4537-97f9-9b57cf6a04c2 binlog]# mysqlbinlog -vv --base64-output=decode-rows mysql-bin.000018
- # at 259
- #170504 11:18:51 server id 3306241 end_log_pos 354 CRC32 0x9d5985ad Query thread_id=155 exec_time=0 error_code=0
- use `xiaoboluo`/*!*/;
- ......
- truncate test_load
- ......
- BEGIN
- /*!*/;
- # at 501
- #170504 11:18:57 server id 3306241 end_log_pos 583 CRC32 0x0e8f7603 Rows_query
- # load data infile '/tmp/test_load.txt' into table test_load # 這裡可以看到load data語句在這裡,這裡是開啟了引數binlog_rows_query_log_events=ON之後記錄的原生sql,預設被加了註釋,主備複製不會執行
- # at 583
- #170504 11:18:57 server id 3306241 end_log_pos 643 CRC32 0xe1c5d4d0 Table_map: `xiaoboluo`.`test_load` mapped to number 341
- # at 643
- #170504 11:18:57 server id 3306241 end_log_pos 713 CRC32 0x31619df3 Write_rows: table id 341 flags: STMT_END_F
- ### INSERT INTO `xiaoboluo`.`test_load` #這裡是用於主備複製的資料變更日誌,可以看到在row格式下被轉換為了row格式
- ### SET
- ### @1=2 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='1' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=4 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='2' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=6 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='null' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=8 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='4' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- # at 713
- #170504 11:18:57 server id 3306241 end_log_pos 744 CRC32 0x18b14b52 Xid = 1245
- COMMIT/*!*/;
- ......
- 解析備庫binlog中是如何記錄的load data語句
- [root@e710d318-d5b4-4bc7-a606-d09f06ff5f5d binlog]# ll
- total 100
- -rw-r----- 1 mysql mysql 990 May 1 01:36 mysql-bin.000001
- -rw-r----- 1 mysql mysql 54766 May 4 00:02 mysql-bin.000002
- -rw-r----- 1 mysql mysql 21376 May 4 09:40 mysql-bin.000003
- -rw-r----- 1 mysql mysql 401 May 4 09:50 mysql-bin.000004
- -rw-r----- 1 mysql mysql 730 May 4 09:51 mysql-bin.000005
- -rw-r----- 1 mysql mysql 730 May 4 11:18 mysql-bin.000006
- -rw-r----- 1 mysql mysql 312 May 4 11:18 mysql-bin.index
- [root@e710d318-d5b4-4bc7-a606-d09f06ff5f5d binlog]# mysqlbinlog -vv --base64-output=decode-rows mysql-bin.000009
- ......
- # at 259
- #170504 11:18:51 server id 3306241 end_log_pos 354 CRC32 0x9d5985ad Query thread_id=155 exec_time=0 error_code=0
- use `xiaoboluo`/*!*/;
- ......
- truncate test_load
- ......
- # at 487
- #170504 11:18:57 server id 3306241 end_log_pos 569 CRC32 0x97dd19e1 Rows_query
- # load data infile '/tmp/test_load.txt' into table test_load # 這裡可以看到load data語句在這裡,這裡是開啟了引數binlog_rows_query_log_events=ON之後記錄的原生sql,預設被加了註釋,主備複製不會執行
- # at 569
- #170504 11:18:57 server id 3306241 end_log_pos 629 CRC32 0x6bef4f90 Table_map: `xiaoboluo`.`test_load` mapped to number 302
- # at 629
- #170504 11:18:57 server id 3306241 end_log_pos 699 CRC32 0x5a86b7f1 Write_rows: table id 302 flags: STMT_END_F
- ### INSERT INTO `xiaoboluo`.`test_load` #這裡是備庫記錄的主庫binlog日誌,可以看到在row格式下被轉換為了row格式,與mixed格式下記錄的內容相同
- ### SET
- ### @1=2 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='1' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=4 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='2' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=6 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='null' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- ### INSERT INTO `xiaoboluo`.`test_load`
- ### SET
- ### @1=8 /* INT meta=0 nullable=0 is_null=0 */
- ### @2='4' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
- # at 699
- #170504 11:18:57 server id 3306241 end_log_pos 730 CRC32 0x983a4a33 Xid = 440
- COMMIT/*!*/;
- ......
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28218939/viewspace-2139837/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- FAQ系列|如何保證主從複製資料一致性
- 解讀MySQL雙主複製的主備資料一致性GPMySql
- 【MySQL】load data語句詳解(一)MySql
- 冗餘資料一致性,到底如何保證?
- 如何保證MySQL和Redis資料一致性?MySqlRedis
- MySQL 5.5使用LOAD DATA INFILE語句匯入資料MySql
- 非同步流複製模式如何保證不丟資料?非同步模式
- 如何保證mongodb和資料庫雙寫資料一致性?MongoDB資料庫
- Zookeeper 如何保證分散式系統資料一致性分散式
- 資料庫和快取的一致性如何保證資料庫快取
- 使用雙非同步後,如何保證資料一致性?非同步
- 如何保證快取和資料庫的一致性?快取資料庫
- MySQL半同步複製資料最終一致性驗證MySql
- 【MySQL】load data語句詳解(二)MySql
- 【MySQL】load data語句詳解(三)MySql
- 趣說 | 資料庫和快取如何保證一致性?資料庫快取
- 複製表結構和資料SQL語句SQL
- Redis主備複製Redis
- Spark CommitCoordinator 保證資料一致性SparkMIT
- 如何保證快取與資料庫的雙寫一致性?快取資料庫
- exp能在什麼級別保證備份資料的一致性呢?
- Oracle如何複製表的sql語句OracleSQL
- MySQL是怎麼保證資料一致性的MySql
- 如何保證快取(redis)與資料庫的雙寫一致性快取Redis資料庫
- 如何保證資料新增或修改成功失敗的一致性?
- Azure Data Factory(二)複製資料
- MySQL半一致性讀導致語句級Binlog複製錯誤MySql
- mysql資料庫的主從複製和主主複製實踐MySql資料庫
- 面試常問:如何保證Redis快取和資料庫的資料一致性NRXW面試Redis快取資料庫
- 資料庫主從複製資料庫
- 資料備份與複製
- kafka 如何保證不重複消費又不丟失資料?Kafka
- mysql主從複製+主備切換MySql
- 針對靜默資料錯誤,如何採用DIX和DIF保證資料一致性?
- 分散式Redis主備複製分散式Redis
- mysql主從複製(冷備)MySql
- 華為GaussDB T資料庫主備物理複製搭建過程資料庫
- 核對主備庫表的資料sql語句(待完善)SQL