超级简单的mysql主从数据库配置攻略以及错误处理
mysql 主從復(fù)制配置
1. 要求
? 1.1 系統(tǒng)平臺一致
? 1.2 數(shù)據(jù)庫版本一致
2. 修改my.cnf文件,主服務(wù)器和備服務(wù)器要求server-id不能一樣
3. 啟動兩側(cè)的數(shù)據(jù)庫
4. 在主服務(wù)器上建立賬號,并且授權(quán)slave,從服務(wù)器可訪問
GRANT REPLICATION SLAVE ON *.* to 'mysql_sync'@'10.10.88.101' identified by '123456';
5. 查看主服務(wù)器狀態(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í)行完此步驟后不要再操作主服務(wù)器MYSQL,防止主服務(wù)器狀態(tài)值變化
6. 配置從服務(wù)器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; ? ?//啟動從服務(wù)器復(fù)制功能
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. 檢查從服務(wù)器復(fù)制功能狀態(tài)(在從服務(wù)器上面執(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 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--主服務(wù)器IP
? ? ? ? ? ? ? ? ? Master_User: mysql_sync ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--主服務(wù)器數(shù)據(jù)庫賬號名稱
? ? ? ? ? ? ? ? ? Master_Port: 3306 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--數(shù)據(jù)庫端口
? ? ? ? ? ? ? ? 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)
配置過程中,因?yàn)楹髞韽闹鲙靋p過來所有的數(shù)據(jù)文件,作為從庫的初始環(huán)境,結(jié)果就報(bào)錯(cuò)如下:
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.
經(jīng)過分析,是因?yàn)閺闹鲙靋p了所有文件,導(dǎo)致server_uuid一致,所以從庫起不來,解決辦法如下:
1. 進(jìn)入到數(shù)據(jù)目錄
cd /app/mysqldata
2. 備份auto.cnf 讓數(shù)據(jù)庫自動生成一個(gè)新的uuid來用
cp auto.cnf auto.cnf.bak
rm -rf auto.cnf
3. 重新啟動主庫以及從庫
查看主庫狀況,重置從庫狀態(tài),啟動slave即可。
轉(zhuǎn)載于:https://blog.51cto.com/dbaway/1703604
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的超级简单的mysql主从数据库配置攻略以及错误处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC++ 6.0 C8051F340 M
- 下一篇: lintcode :Partition