作者:kenson4930 | 来源:互联网 | 2024-10-19 19:45
主库:my.cnf
server-id=1 ######只能有一个server-id
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
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_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
Slave_SQL_Running: Yes ####必须是yes
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
同步成功后主从重启等等一般不会造成同步不成功的问题