固然了,要想解決問題得先有環境。
一主一從的配置流程:
主:先配置DNS解析,實驗環境能夠利用 /etc/hosts 解析
vim /etc/hosts
192.168.122.45 master1
192.168.122.46 master2
從機不用在配置,經過scp發送到從機
scp /etc/hosts master2:/etc
1 啓動二進制日誌,服務器ID,GTID
vim /etc/my.cnf
log-bin
server-id=1
gtid_mode=ON
enforce_gtid_consistency=1
重啓mysql
systemctl restart mysqldmysql
date +%F
-mysql-all.sql還恢復手動同步數據
set sql_log_bin=0;sql
source /tmp/2018-3-20-mysql-full.sql 3.設置主服務器 mysql> change master to
master_host='master1',br/>master_user='rep',
master_password='QianFeng@123',
master_auto_position=1;vim
start slave; show slave status\G; 到這裏沒什麼問題一主一從就部署完成了,若是有錯誤可借鑑如下方法排錯,但願能幫助到你們! 例: *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.60.159 Master_User: backup Master_Port: 3311 Connect_Retry: 60 Master_Log_File: mysql-bin.000012 Read_Master_Log_Pos: 274863854 Relay_Log_File: mysql-relay-bin.000007 Relay_Log_Pos: 2160037 Relay_Master_Log_File: mysql-bin.000012 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error executing row event: 'Table 'panda.t' doesn't exist'
Skip_Counter: 0
Exec_Master_Log_Pos: 2159824
Relay_Log_Space: 274866725 服務器
錯誤緣由:主庫刪除的表在從庫中不存在,致使從庫在遇到刪除不存在表的錯誤時沒法繼續同步。 解決方法:利用slave-skip-errors參數,跳過對於的1146錯誤(這個參數是一個只讀的,須要在配置文件中修改,並重啓從庫) 一、在my.cnf的[mysqld]下面添加slave_skip_errors=1146
二、重啓從庫 systemctl restart mysqldide
三、在從庫上啓動同步
start slave;rest
四、去掉my.cnf中的slave_skip_errors=1146
五、重啓從庫 systemctl restart mysqld日誌
六、啓動從庫複製
start slave;code
例: server
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.60.159
Master_User: backup
Master_Port: 3311
Connect_Retry: 60
Master_Log_File: mysql-bin.000012
Read_Master_Log_Pos: 274863854
Relay_Log_File: mysql-relay-bin.000007
Relay_Log_Pos: 2160037
Relay_Master_Log_File: mysql-bin.000012
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error executing row event: 'Table 'panda.t' doesn't exist'
Skip_Counter: 0
Exec_Master_Log_Pos: 2159824
Relay_Log_Space: 274866725 ip
錯誤緣由:主和從的UUID一致,需改動從機的UUID便可 解決方法: 1.在從機上 cd /var/lib/mysql ls 看到auto.cnf vim auto.cnf 隨意改動一個數字便可 保存並退出 systemctl restart mysqld 2.進入Mysql start slave; 成功 好了,到這裏就結束了,有錯的地方望你們批評和建議!!!