1.環境:centos6.5
[root@mysql-m1 mysql-5.7.10]# cat /etc/redhat-release
CentOS release 6.5 (Final)
主機:
現在是mysql-m1資料庫已經搭建好,我使用自己的虛拟機進行clone 就省去多次安裝資料庫。
2.確定兩個主庫的server_id log-bin 開啟 并且三個庫的server_id 不同:
3.master上建立測試庫和表:
3.1登陸資料庫mysql-m1建立庫test01 和表h1:
[root@mysql-m1 tmp]# mysql -uroot -p -S /tmp/mysql.sock
3.2登陸資料庫mysql-m2建立庫test01 和表和h2:
以下不停庫鎖表,自動切割bin-log日志,全量備份bin-log,導入從庫中(此方法隻适合5.5版本以下的資料庫備份,不适合5.7版本的資料庫備份,有待驗證)(不是這篇文檔的步驟)
适合5.7版本的多元同步的資料庫備份(不同的表同步到一個資料庫中):
4.slave上操作:
分别在Slave上把Master_1和Master_2的資料導入Slave伺服器,在導入前先修改從庫的MySQL存儲master-info和relay-info的方式,即從檔案存儲改為表存儲,在my.cnf裡添加以下選擇:(注意此修改的是從庫)
或者再MySQL從庫指令行操作:
把資料導入資料庫:
[root@mysql-s tmp]# mysql -uroot -p -S /tmp/mysql.sock </tmp/m2.sql
[root@mysql-s tmp]# mysql -uroot -p -S /tmp/mysql.sock </tmp/m1.sql
5.在mysql-m1和mysql-m2上建立複制賬号:
這個操作跟MySQL 5.7之前版本一樣:
在mysql-m1上建立
在mysql-m2上建立
6.在slave從庫上操作進行change master :
[root@mysql-s ~]# mysql -uroot -p123456 -S /tmp/mysql.sock -e "SHOW SLAVE STATUS FOR CHANNEL 'mysql-m1'\G"|egrep "Slave_IO_Running|Slave_SQL_Running"
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Connecting (報錯) 此處為yes才是正常的
Slave_SQL_Running: Yes
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
7.同步報錯解決方法:
7.1.看錯誤日志:
[root@mysql-s ~]# cat /aliyun/data/mysql/mysql_3306.err
7.2.檢查防火牆是否關閉:
(從庫本地和主庫本地的防火牆)
7.3. 修改/ect/my.cnf中server_id 未生效:
7.4.但是還是報錯:
原因是mysql-s 虛拟機是基于mysql-m1的虛拟機克隆過來的,mysqlm1上的檔案auto.cnf和mysql-s /mysql=m2上檔案的auto.cnf 是一樣的,是以報錯
可以通過檢視performance_schema相關的表檢視同步狀态,執行指令:
mysql> stop slave;(停止時必須同時開啟各個slave,否則不能同步)
8.MySQL 5.7的多源複制用處:
8.1、MySQL 5.7的多源複制,能有效的解決分庫分表的資料統計問題,同時也可以實作在一台從伺服器對多台主伺服器的資料備份。
8.2、MySQL 5.7的多源複制的出現,我們就不需要使用MariaDB 的多主一從的架構了,讓很多小夥伴又看到了新的希望。
參考資料:
<a href="http://dev.mysql.com/doc/refman/5.7/en/change-master-to.html">http://dev.mysql.com/doc/refman/5.7/en/change-master-to.html</a>
<a href="http://www.longlong.asia/2015/10/21/mysql57-new-features.html">http://www.longlong.asia/2015/10/21/mysql57-new-features.html</a>
MySQL-5.7文檔看考資料:
<a href="http://www.cnblogs.com/xuanzhi201111/p/5148113.html">http://www.cnblogs.com/xuanzhi201111/p/5148113.html</a>
mysql多元複制資料位址
<a href="http://www.mamicode.com/info-detail-1189601.html">http://www.mamicode.com/info-detail-1189601.html</a>
mysql 資料庫5.7編譯安裝
本文轉自 wjw555 51CTO部落格,原文連結:http://blog.51cto.com/wujianwei/2066178