主;
1.
my.cnf
server-id = 1
log-bin=mysql-bin
read-only=0 #主機,讀寫都可以,1 只能讀
binlog-do-db=dbname --要同步的數據庫名稱,多個寫多行
binlog-ignore-db=dbname --不要同步的數據庫名稱,多個寫多行
2.
重啓
service mysqld start
3.創建用戶
grant replication slave on *.* to repuser@'%' identified by '1234';
flush privileges;
4.
show master status; 記錄file: binlog.000016 和position:7333
cd .
從
1.my.cnf server-id = 2
2.看與主庫是否通信
付:stop slave;
3.
change master to master_host='192.168.1.45', master_user='repuser', master_password='1234', master_log_file='mysql-bin.000016', master_log_pos=9390;
4.
開啓 start slave;
5. 查看是否通信
show slave status \G;
如出現
Slave_IO_Running: Yes(網絡正常,如果服務器斷網或沒啓動則爲NO);
Slave_SQL_Running: Yes(表結構正常,如果表結構不一樣,以及數據不一樣則爲NO)
都爲YES表示同步正常、
ok;