mysql5.6指定具体数据库ranzhidb进行同步:
以下在MySQL slave从库上的配置参数可以解决在master主库上跨库操作,插入和删除记录时,不同步数据到slave从库上的问题
master主库配置文件:
[root@cacti init.d]# egrep "binlog-format|server-id|log-bin" /etc/my.cnf
binlog-format = MIXED(可以为row模式)
server-id = 1131053306
log-bin = /data/mysql/binlog/mysql-bin
slave从库配置文件:
replicatewild*参数只需要在从库的配置文件配置,主库的配置文件上不需要配置
[root@cacti init.d]# egrep "server-id|log-bin|replicate_wild_*" /data/mysql3307/etc/my.cnf
replicate_wild_do_table=ranzhidb.%
replicate_wild_ignore_table=information_schema.%
replicate_wild_ignore_table=performance_schema.%
replicate_wild_ignore_table=Yiqiv_monitor.%
replicate_wild_ignore_table=cacti.%
replicate_wild_ignore_table=itop.%
replicate_wild_ignore_table=itopdb.%
replicate_wild_ignore_table=jumpserver.%
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=lepus.%
replicate_wild_ignore_table=mtoyydb.%
replicate_wild_ignore_table=tjyy.%
replicate_wild_ignore_table=zabbix.%
log-bin = /data/mysql3307/binlog/mysql-bin
server-id = 1131053307
[root@cacti mysql3307]# mysql -uroot -p'test321abc' -S /tmp/mysql3307.sock -e "show slave status\G"|egrep "Slave_IO_Running|Slave_SQL_Running|Replicate_Wild_*"
Warning: Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Wild_Do_Table: ranzhidb.%
Replicate_Wild_Ignore_Table: information_schema.%,performance_schema.%,Yiqiv_monitor.%,cacti.%,itop.%,itopdb.%,jumpserver.%,mysql.%,lepus.%,mtoyydb.%,tjyy.%,zabbix.%
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
可以在slave的my.cnf的配置文件内同时指定多个数据库中的表进行同步:
mysql -uroot -p'test321abc' -S /tmp/mysql3307.sock -e "show slave status\G"|egrep "Slave_IO_Running|Slave_SQL_Running|ReplicateWild*"
Warning: Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Wild_Do_Table: ranzhidb.%,test001.%
Replicate_Wild_Ignore_Table: information_schema.%,performance_schema.%,Yiqiv_monitor.%,cacti.%,itop.%,itopdb.%,jumpserver.%,mysql.%,lepus.%,mtoyydb.%,tjyy.%,zabbix.%
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
[root@cacti ~]# egrep "server-id|log-bin|replicatewild*" /data/mysql3307/etc/my.cnf
replicate_wild_do_table=ranzhidb.%
replicate_wild_do_table=test001.%
replicate_wild_ignore_table=information_schema.%
replicate_wild_ignore_table=performance_schema.%
replicate_wild_ignore_table=Yiqiv_monitor.%
replicate_wild_ignore_table=cacti.%
replicate_wild_ignore_table=itop.%
replicate_wild_ignore_table=itopdb.%
replicate_wild_ignore_table=jumpserver.%
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=lepus.%
replicate_wild_ignore_table=mtoyydb.%
replicate_wild_ignore_table=tjyy.%
replicate_wild_ignore_table=zabbix.%
log-bin = /data/mysql3307/binlog/mysql-bin
server-id = 1131053307
提示:前提是这两个数据库ranzhidb和test001 以及库里面的表要在slave上存在,这样复制的时候,slave上同步时不会报错