1、修改MySQL配置:
主庫配置
server-id = 3
binlog-do-db=xmcp_gxfc #the db need to sync
binlog-ignore-db = mysql #不需要同步的數(shù)據(jù)庫
binlog-ignore-db = redmine #不需要同步的數(shù)據(jù)庫
log_slave_updates = 1
binlog_format=mixed
relay_log = /usr/local/mysql/relay_log/mysql-relay-bin
read_only = 1
創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),儀征網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:儀征等地區(qū)。儀征做網(wǎng)站價(jià)格咨詢:18982081108
2創(chuàng)建賬號
grant replication slave on . to 'slave2'@'%' identified by 'FjAfj6#xajot#K%V';
grant replication slave on . to 'slave3'@'%' identified by 'FjAfj6#xajot#K%V';
mysql>flush privileges;
mysql> show master status;
記錄下 File為mysql-bin.000001
記錄下 position為 154
3、修改從庫MySQL配置:
從庫配置:
server-id = 5
log-bin = mysql-bin
replicate-do-db=xmcp_gxfc
binlog_format=mixed
relay_log=/usr/local/mysql/relay_log/mysql-relay-bin
read_only = 1
4、執(zhí)行同步命令
mysql>change master to master_host='10.2.2.2',master_user='slave2',master_password='FjAfj6#xajot#K%V',master_log_file='mysql-bin.000001',master_log_pos=154;
mysql>start slave;
5、檢查從數(shù)據(jù)庫狀態(tài):
mysql> show slave status\G;
注:Slave_IO_Running及Slave_SQL_Running進(jìn)程必須正常運(yùn)行,即YES狀態(tài),否則說明同步失敗。可用這兩項(xiàng)判斷從服務(wù)器是否掛掉
mysql > SET GLOBAL server_id=2;
6、Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
原因分析:
mysql 5.6的復(fù)制引入了uuid的概念,各個(gè)復(fù)制結(jié)構(gòu)中的server_uuid得保證不一樣,但是查看到直接copy data文件夾后server_uuid是相同的,show variables like '%server_uuid%';
解決方法:
找到data文件夾下的auto.cnf文件,修改里面的uuid值,保證各個(gè)db的uuid不一樣,重啟db即可
場景二:創(chuàng)建主從關(guān)系時(shí)copy了同樣的my.cnf文件,報(bào)錯(cuò)
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids;
原因分析:
和server_uuid類似,servier_id也得保證不一樣
解決方法:
找到my.cnf配置文件中的server_id,修改從庫的server_id保證和復(fù)制結(jié)構(gòu)中的其他db不一樣,重啟db即可