主库:my.cnf
server-id=1 ######只能有一个server-id
binlog-do-db=test ####需要同步的数据库,多个多行写
log-bin=mysql-bin
master-host = 192.168.0.121
master-user = copy ###授权远程连接
master-password = 1
master-port = 3306
从库:my.cnf
server-id=2 ######只能有一个server-id
binlog-do-db=test ####需要同步的数据库,多个多行写
log-bin=slave-bin
master-host = 192.168.0.120
master-user = copy ###授权远程连接
master-password = 1
master-port = 3306
主从/usr/local/mysql/bin/mysql -uroot -p1
mysql>reset master ######重置所有binlog日志
mysql>show slave status;
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.120
Master_User: copy
Master_Port: 3306
Connect_Retry: 60 ####闲置时定期同步可更改master.info
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 106 ######同步的pos位置
Relay_Log_File: localhost-relay-bin.000005
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes ####必须是yes 和主库IO通信判断
Slave_SQL_Running: Yes ####必须是yes 自身SQL执行判断,
为NO时,可能从库与主库数据表结构不一致导致执行SQL语句出错,执行 stop slave; set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; start slave;
Replicate_Do_DB:
Replicate_Ignore_DB:
若同步不成功试着删除所有同步有关数据
/etc/init.d/mysql stop
rm -rf /usr/local/mysql/var/localhost-relay-bin.* master.info mysql-bin.* relay-log.info
/etc/init.d/mysql start
同步成功后主从重启等等一般不会造成同步不成功的问题