Introduced
MySQL5.7 official documentation on the relevant parameters: Https://dev.mysql.com/doc/refman/5.7/en/change-replication-filter.html
Dynamic modification is supported in version 5.7, and the previous version requires a restart of the database:
STOP SLAVE SQL_THREAD;CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB=(demo);START SLAVE SQL_THREAD;
Problem description
Executes the statement in the main library if use DB is not used;
Statements that create a new table are not executed from the library, resulting in a master-slave error
Scene Recurrence
From the Library configuration:
replicate-ignore-db = testreplicate-do-db = abc
Main Library Operations:
22:29:04test>use test;Database changed22:30:26test>create table abc.t0417(id int,name varchar(20));Query OK, 0 rows affected (0.08 sec)22:31:37abc>use test;Database changed22:32:05test>insert into abc.t0417 values(1,‘a‘);Query OK, 1 row affected (0.02 sec)
A SQL thread error occurred from the Library state:
22:31:07abc>show slave status \g*************************** 1. Row *************************** slave_io_state:waiting for master to send event Master_hos t:192.168.136.128 Master_user:repl master_port:3306 connect_retry:60 master_log_file:mysql-bin.000015 read_master_log_pos:8478 Relay_log_file:cptest-rel ay-bin.000007 relay_log_pos:1292 relay_master_log_file:mysql-bin.000015 Slave_io_runni Ng:yes slave_sql_running:no replicate_do_db:abc replicate_ignore_db:test Re Plicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table: last_errno:1146 last_error:error executing row event: ' Table ' abc.t0417 ' doesn ' t exist ' skip_counter:0 exec_master_log_pos:8235 Relay_log_space:1709 Until_condition:none until_log_file:until_log_pos:0 Master_ssl_allowed:no Master_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert: Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:NULLMaster_SSL_Verify_Server_Cert: No last_io_errno:0 last_io_error:last_sql_errno:1146 last_s Ql_error:error executing row event: ' Table ' abc.t0417 ' doesn ' t exist ' replicate_ignore_server_ids:master_s Erver_id:1 master_uuid:4ac80f6d-8063-11e7-9d63-000c291d913c master_info_file:/data/mysql/m Ysql3309/master.info sql_delay:0 sql_remaining_delay:null slave_sql_running_state: master_retry_count:86400 Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestam p:180416 22:32:20 master_ssl_crl:master_ssl_crlpath:retrieved_gtid_set:4ac80f6d-8063-11e7-9d63-000c291d913 c:3609-3630 executed_gtid_set:4ac80f6d-8063-11e7-9d63-000c291d913c:1:3609-3629,a1c747e9-4170-11e8-883f-000c29c 6b279:1 auto_position:01 Row in Set (0.00 sec)
Solve the problem
To change the configuration from the library:
#replicate-ignore-db = test#replicate-do-db = abcreplicate_wild_do_table = abc.%replicate_wild_ignore_table = test.%
Main Library Operations:
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 65Server version: 5.6.35-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.[email protected] 00:39:16(none)>use test;Database changed[email protected] 00:39:32test>create table abc.test0417(id int,name varchar(20));Query OK, 0 rows affected (0.17 sec)[email protected] 00:40:25test>insert into abc.test0417 values(1,‘b‘);Query OK, 1 row affected (0.11 sec)
From library State:
[email protected] 00:39:06 (none) >show slave status \g*************************** 1. Row *************************** slave_io_state:waiting for master to send event Master_hos t:192.168.136.128 Master_user:repl master_port:3306 connect_retry:60 master_log_file:mysql-bin.000015 read_master_log_pos:9644 Relay_log_file:cptest-rel ay-bin.000010 relay_log_pos:771 relay_master_log_file:mysql-bin.000015 Slave_io_runnin G:yes Slave_sql_running:yes Replicate_Do_DB:Replicate_Ignore_DB:Replicate _do_table:replicate_ignore_table:replicate_wild_do_table:abc.% replicate_wild_ignore_table:test.% last_errno:0 last_error:skip_counter:0 exec_master_log_pos:964 4 relay_log_space:945 Until_condition:none until_log_file:until_log_pos:0 Master_ssl_allowed:no Master_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher: Master_ssl_key:seconds_behind_master:0master_ssl_verify_server_cert:no last_io_errno:0 last_io_error:last_sql_errno:0 Last_sql_error:replicate_ignore_server_ids: Master_server_id:1 master_uuid:4ac80f6d-8063-11e7-9d63-000c291d913c master_in Fo_file:/data/mysql/mysql3309/master.info sql_delay:0 sql_remaining_delay:null Slave_S Ql_running_state:slave have read all relay log; Waiting for the slave I/O thread to update it master_retry_count:86400 Master_bind:last _io_error_timestamp:last_sql_error_timestamp:master_ssl_crl:master_ssl_crlpath:retrieved_gtid_set:4ac80f6d-8063-11e7-9d63-000c291d913c:3609-3635 Executed_Gtid_Set : 4ac80f6d-8063-11e7-9d63-000c291d913c:1:3609-3635,a1c747e9-4170-11e8-883f-000c29c6b279:1-6 Auto_Position: (0.00 sec) [email protected] 00:40:54 (None) >select * from abc.test0417;+------+------+| ID | Name |+------+------+| 1 | b |+------+------+1 row in Set (0.00 sec)
Summarize
- Using the use DB is required for replicate_do_db and replicate_ignore_db two parameters when operating in the main library;
- It is recommended to use replicate_wild_do_table,
Replicate_wild_ignore_table
About the pits of replicate_do_db and replicate_ignore_db