超级简单的mysql主从数据库配置攻略以及错误处理
mysql 主從復制配置
1. 要求
? 1.1 系統(tǒng)平臺一致
? 1.2 數據庫版本一致
2. 修改my.cnf文件,主服務器和備服務器要求server-id不能一樣
3. 啟動兩側的數據庫
4. 在主服務器上建立賬號,并且授權slave,從服務器可訪問
GRANT REPLICATION SLAVE ON *.* to 'mysql_sync'@'10.10.88.101' identified by '123456';
5. 查看主服務器狀態(tài)
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File ? ? ? ? ?| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| dbtest.000005 | ? ? ?414 | ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ? |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.15 sec)
注意:執(zhí)行完此步驟后不要再操作主服務器MYSQL,防止主服務器狀態(tài)值變化
6. 配置從服務器Slave
mysql> change master to master_host='10.10.88.100',master_user='mysql_sync',master_password='123456',master_log_file='dbtest.000005',master_log_pos=414;
mysql> start slave; ? ?//啟動從服務器復制功能
mysql> change master to master_host='10.10.88.100',master_user='mysql_sync',master_password='123456',master_log_file='dbtest.000007',master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.12 sec)
mysql> start slave;
Query OK, 0 rows affected (0.24 sec)
7. 檢查從服務器復制功能狀態(tài)(在從服務器上面執(zhí)行檢查):
mysql> show slave status\G
mysql> show slave status\G
*************************** 1. row ***************************
? ? ? ? ? ? ? ?Slave_IO_State: Waiting for master to send event
? ? ? ? ? ? ? ? ? Master_Host: 10.10.88.100 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--主服務器IP
? ? ? ? ? ? ? ? ? Master_User: mysql_sync ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--主服務器數據庫賬號名稱
? ? ? ? ? ? ? ? ? Master_Port: 3306 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--數據庫端口
? ? ? ? ? ? ? ? Connect_Retry: 60
? ? ? ? ? ? ? Master_Log_File: dbtest.000005
? ? ? ? ? Read_Master_Log_Pos: 414
? ? ? ? ? ? ? ?Relay_Log_File: DBTEST2-relay-bin.000002
? ? ? ? ? ? ? ? Relay_Log_Pos: 280
? ? ? ? Relay_Master_Log_File: dbtest.000005
? ? ? ? ? ? ?Slave_IO_Running: Yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? --狀態(tài),必須為Yes
? ? ? ? ? ? Slave_SQL_Running: Yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? --狀態(tài),必須為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: 414
? ? ? ? ? ? ? Relay_Log_Space: 455
? ? ? ? ? ? ? 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: 1
? ? ? ? ? ? ? ? ? Master_UUID: 73b077c6-626d-11e5-8f5b-000c29e840c1
? ? ? ? ? ? ?Master_Info_File: /app/mysqldata/master.info
? ? ? ? ? ? ? ? ? ? SQL_Delay: 0
? ? ? ? ? SQL_Remaining_Delay: NULL
? ? ? Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
? ? ? ? ? ?Master_Retry_Count: 86400
? ? ? ? ? ? ? ? ? Master_Bind:?
? ? ? Last_IO_Error_Timestamp:?
? ? ?Last_SQL_Error_Timestamp:?
? ? ? ? ? ? ? ?Master_SSL_Crl:?
? ? ? ? ? ?Master_SSL_Crlpath:?
? ? ? ? ? ?Retrieved_Gtid_Set:?
? ? ? ? ? ? Executed_Gtid_Set:?
? ? ? ? ? ? ? ? Auto_Position: 0
1 row in set (0.00 sec)
配置過程中,因為后來從主庫cp過來所有的數據文件,作為從庫的初始環(huán)境,結果就報錯如下:
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; ?these UUIDs must be different for replication to work.
經過分析,是因為從主庫cp了所有文件,導致server_uuid一致,所以從庫起不來,解決辦法如下:
1. 進入到數據目錄
cd /app/mysqldata
2. 備份auto.cnf 讓數據庫自動生成一個新的uuid來用
cp auto.cnf auto.cnf.bak
rm -rf auto.cnf
3. 重新啟動主庫以及從庫
查看主庫狀況,重置從庫狀態(tài),啟動slave即可。
轉載于:https://blog.51cto.com/dbaway/1703604
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的超级简单的mysql主从数据库配置攻略以及错误处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC++ 6.0 C8051F340 M
- 下一篇: MySQL 表空间