標籤:mysql 主從複製
主從複製步驟
1:開啟主庫binlog功能
查看3306 是否開啟
grep log-bin /etc/my.cnf
查看是否不一樣
2:確保server-id 不同
grep server-id /etc/my.cnf
grep server-id /data/3307/my.cnf
3:主庫授權 複製的使用者rep
grant replication slave on *.* to [email protected]‘192.168.1.102‘ identified by ‘2017‘;
查看是否授權成功
4:鎖表,查看binlog 位置點
先鎖表 保證資料庫一致
flush table with read lock;
show master status; 看看備份點
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000053 | 339 | | |
+------------------+----------+--------------+------------------+
5.新開視窗匯出全備
mysqldump -uroot -p2017 -A -B --events -S /tmp/mysql.sock|gzip >/home/chaofu/rep_bak_$(date +%F).sql.gz
6: unlock table 解除鎖表
從庫:
1:確保server-id 不同
2:把主庫的資料恢複到 從 庫
gzip -d rep_bak.sql.gz
mysql -uroot -p -S /data/3307/mysql.sock < /home/chaofu/rep_bak_2017-11-21.sql
3:找位置點,配置master.info
CHANGE MASTER TO
MASTER_HOST=‘192.168.1.102‘,
MASTER_PORT=3306,
MASTER_USER=‘rep‘,
MASTER_PASSWORD=‘2017‘,
MASTER_LOG_FILE=‘mysql-bin.000053‘,
MASTER_LOG_POS=339;
find /data/3307/data -type -f -name "*.info"
4: 開啟 備份開關
start slave;
show slave status \G;
從庫兩個線程
5:測試
主從複製原理圖
本文出自 “9124122” 部落格,請務必保留此出處http://9134122.blog.51cto.com/9124122/1983933
mysql主從複製