跨库复制
原创
©著作权归作者所有:来自51CTO博客作者igoodful的原创作品,请联系作者获取转载授权,否则将追究法律责任
一.从库执行:show slave status\G;
admin@a8-dba-cloud-db00.wh ((none)) > show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.10.10.10
Master_User: mysqlsync
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 3543191
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 3543396
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 3543191
Relay_Log_Space: 3543589
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: 0
Master_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: 176689962
Master_UUID: 978aaabd-82b2-11ea-b0b5-e4434bac7bda
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 978aaabd-82b2-11ea-b0b5-e4434bac7bda:1-3692
Executed_Gtid_Set: 978aaabd-82b2-11ea-b0b5-e4434bac7bda:1-3692
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
Sat May 2 00:58:24 2020
二.现象
使用replicate_do_db和replicate_ignore_db时有一个隐患,跨库更新时会出错。
如设置 replicate_do_db=test
use mysql;
update test.table1 set ......
第二句将不会被执行
如设置 replicate_ignore_db=mysql
use mysql;
update test.table1 set ......
第二句会被忽略执行
原因是设置replicate_do_db或replicate_ignore_db后,MySQL执行sql前检查的是当前默认数据库,所以跨库更新语句被忽略。
可以使用 replicate_wild_do_table 和 replicate_wild_ignore_table 来解决跨库更新的问题,如:
replicate_wild_do_table=test.%
或
replicate_wild_ignore_table=mysql.%
这样就可以避免出现上述问题了