1. 程式人生 > >linux下mysql主從配置詳細教程

linux下mysql主從配置詳細教程

different form file 判斷 pda work grant _for 從數據

1、修改MySQL配置:
主庫配置
server-id = 3
binlog-do-db=xmcp_gxfc #the db need to sync
binlog-ignore-db = mysql #不需要同步的數據庫
binlog-ignore-db = redmine #不需要同步的數據庫
log_slave_updates = 1
binlog_format=mixed
relay_log = /usr/local/mysql/relay_log/mysql-relay-bin
read_only = 1

2創建賬號
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、執行同步命令

執行同步命令,設置主數據庫ip,同步帳號密碼,同步位置

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、檢查從數據庫狀態:
mysql> show slave status\G;

註:Slave_IO_Running及Slave_SQL_Running進程必須正常運行,即YES狀態,否則說明同步失敗。可用這兩項判斷從服務器是否掛掉

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的復制引入了uuid的概念,各個復制結構中的server_uuid得保證不一樣,但是查看到直接copy data文件夾後server_uuid是相同的,show variables like ‘%server_uuid%‘;

解決方法:

找到data文件夾下的auto.cnf文件,修改裏面的uuid值,保證各個db的uuid不一樣,重啟db即可

場景二:創建主從關系時copy了同樣的my.cnf文件,報錯

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保證和復制結構中的其他db不一樣,重啟db即可

linux下mysql主從配置詳細教程