需求:
将主库的表同步到从库,数据库名不一样,映射关系如下:
(pres_eims,riskdb),(pres_system,pres_system_slave),(pres_business,pre_business_slave),(pres_sp_business,pres_sp_business)
问题描述,两个线程都正常,relay_log中也有日志写入,但是没有写入数据库中
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
relay-log中有日志,但是没有写入从库
1、使用mysqlbinlog工具查看二进制日志:
mysqlbinlog mysql-relay-bin-126.000004 --base64-output=decode-row -vvv --skip-gtids -vv | grep -B 1 -i 'insert into'
能查到日志。
问题解决:
去掉以下两个配置,
Replicate_Do_DB:
Replicate_Ignore_DB
这两个参数如果设置了,会导致Replicate_Rewrite_DB不生效。
完整的/etc/my.cnf
[mysqld]
character-set-server=utf8
server-id=3
log_bin=mysql-bin
relay_log=mysql-relay-bin
relay-log-index=mysql-relay-bin.index
log_slave_updates=1
sync_relay_log=1
sync_relay_log_info=1
sync_master_info=1
sync_source_info=1
slave-skip-errors=all
#replicate-do-db=pres_eims,pres_system,pres_business,pres_sp_business,pres_options,test
#replicate-do-db=pres_system
#replicate-do-db=pres_business
#replicate-do-db=pres_sp_business
#replicate-ignore-db=pres_options
#replicate-ignore-db=test
#replicate-ignore-db=mysql
#replicate-ignore-db=trmp_business
#replicate-ignore-db=my_database
#replicate-ignore-db=information_schema
#replicate-ignore-db=pres_iams
replicate-rewrite-db=pres_eims -> riskdb
replicate-rewrite-db=pres_system -> pres_system_slave
replicate-rewrite-db=pres_business -> pre_business_slave
replicate-rewrite-db=pres_sp_business -> pres_sp_business
#replicate-rewrite-db=test -> test
#replicate-wild-do-table=riskdb.test01
#replicate-wild-do-table=riskdb.test02
port = 33066
basedir = /opt/mysql-8
datadir = /storage/mysql-8/data
#socket = /var/run/mysql/mysql.sock
#socket = /tmp/mysql/mysql.sock
character-set-server = utf8
#collation-server = unf8mb4_unicode_ci
max_connections = 1000
max_allowed_packet = 4000M
default_authentication_plugin = mysql_native_password
secure_file_priv = ''
[client]
port = 33066
#socket = /var/run/mysql/mysql.sock
#socket = /tmp/mysql/mysql.sock
附排查过程中使用的mysql语句:
how master status;
show slave hosts;
show variables like 'binlog_format';
show variables like '%binlog_format';
show variables;
set @@log_slave_updates=true
show variables like 'log-slave-updates';
show variables like '%server%id%';
show slave status;
show processlist;
flush table with read lock;
UNLOCK tables;
show tables ;
show VARIABLES like 'CHARACTER_set_%'
show VARIABLES like 'COLLATION_%'
show variables like 'character_set_server'
show VARIABLES like 'init_connect'
show variables like '%relay%'
show variables like '%version%'
select @@binlog_format;