今天小編就爲大家分享一篇關於Mysql主從複製注意事項的講解,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
一、報錯error connecting to master '[email protected]:x' - retry-time: 60 retries: 86400
今天搭建mysql主從複製,一直報這個錯。我是在一臺虛擬機上使用多實例創建的2個不同端口的數據庫,查了很久,才解決。
1.檢查主從複製的用戶名密碼;
2.檢查MASTER_LOG_FILE和MASTER_LOG_POS。
記住配置從庫的命令,這些參數都要參考主庫的配置:
mysql> CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=3308, MASTER_USER='root', MASTER_PASSWORD='oldboy123', MASTER_LOG_FILE='mysql-bin.000007', MASTER_LOG_POS=797;
查詢同步結果:
mysql> show slave status \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 127.0.0.1 Master_User: root Master_Port: 3308 Connect_Retry: 60 Master_Log_File: mysql-bin.000007 Read_Master_Log_Pos: 797 Relay_Log_File: mysql-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000007 Slave_IO_Running: Yes 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: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 797 Relay_Log_Space: 409 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 3308
同步結果看3項:Slave_IO_Running(I/O線程狀態),Slave_SQL_Running(SQL線程狀態),Seconds_Behind_Master(複製過程中從庫比主庫延遲的秒數)。
二、從庫出現衝突無法複製。可以將同步指針向下移動一個,如果多次不同步,重複操作。
mysql> stop slave; Query OK, 0 rows affected (0.02 sec) mysql> set global sql_slave_skip_counter=1; Query OK, 0 rows affected (0.00 sec) mysql> start slave; Query OK, 0 rows affected (0.01 sec)
三、當前從庫還要作爲其他從庫的主庫。在從庫的my.cnf加入如下參數,並修改server_id和log-bin的配置(去掉註釋,修改默認配置),重啓服務。
log-slave-updates log-bin = /data/3309/data/mysql-bin #根據實際情況寫 expire_logs_days = 7 #相當於find /data/3309/data -type f -name "mysql-bin.000* -mtime +7 | xargs rm -f"
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對神馬文庫的支持。如果你想了解更多相關內容請查看下面相關鏈接