linux之mysql57雙主模式
1 準(zhǔn)備環(huán)境 三臺(tái)機(jī)子 master slave1 slave2 主從配置 主從配置看?http://www.itdecent.cn/p/0459d25269c2
2 主環(huán)境(master)配置
[mysqld]
log_bin=mysql-bin
server-id=2
sync-binlog=1
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performation_schema
binlog-ignore-db=sys
relay_log=mysql-relay-bin
log_slave_updates=1
auto_increment_offset=2
auto_increment_increment=2
3 從環(huán)境(slave1改為主)配置
[mysqld]
log_bin=mysql-bin
server-id=2
sync-binlog=1
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performation_schema
binlog-ignore-db=sys
relay_log=mysql-relay-bin
log_slave_updates=1
auto_increment_offset=2
auto_increment_increment=2
4 其實(shí)區(qū)別就在于 server-id 這是必需不同的,其次 就是auto_increment_offset 偏移變量 原因很簡(jiǎn)單 雙主的都具有讀寫功能
5? 授權(quán)(master 和slave1都要)
mysql -uroot -p
grant replication slave on *.* to 'root'@'%' identified by 'Yumeko213@';
flush privileges;
6 設(shè)置關(guān)聯(lián) 注意:
1)互為主從那就需要show master status; 查看各自的?file 和 Position和端口號(hào) 知道各自的用戶名密碼就是上一步授權(quán)的
master_log_file對(duì)應(yīng) file, Position對(duì)應(yīng) master_log_pos
2)master作為slave1的從庫(kù)
stop slave;
change master to master_host='192.168.106.129',master_port=3306,master_user='root',master_password='Yumeko213@',master_log_file='mysql-bin.000001',master_log_pos=154;
start slave;
3)slave1作為master 的從庫(kù)
stop slave;
change master to master_host='192.168.106.128',master_port=3306,master_user='root',master_password='Yumeko213@',master_log_file='mysql-bin.000001',master_log_pos=154;
start slave;
4) 分別 查看 show slave status \G;
?如出現(xiàn)問(wèn)題?
?stop slave;? ? reset slave;? ? start slave;
根據(jù)Last_SQL_Errno 提示解決
5 測(cè)試
比如master中創(chuàng)建庫(kù)和表? create database yumeko;? create table yumeko;?
比如slave1中創(chuàng)建庫(kù)和表??create database yumeko1;? create table yumeko1;?
在各自刪除,一切正常我們的雙主配置就成功了 驚不驚喜 意不意外 其實(shí)就是這么簡(jiǎn)單!