Mysql配置從庫延遲應用
延遲應用主要用於防範邏輯錯誤,如主庫誤修改、誤刪除等,從庫在設定時間內,還沒有應用這些錯誤的SQL,則可以在從庫獲取誤操作之前的資料。
Mysql透過指定從庫的master_delay選項來實現延遲應用。
1、安裝Mysql並配置主從
參考http://blog.itpub.net/28536251/viewspace-2138854/分別在兩節點安裝Mysql。
參考http://blog.itpub.net/28536251/viewspace-2138928/或者http://blog.itpub.net/28536251/viewspace-2139007/配置主從。
2、從庫配置延遲應用
(root@localhost)[(none)] stop slave sql_thread;
Query OK, 0 rows affected (0.15 sec)
(root@localhost)[(none)] change master to master_delay=60;
Query OK, 0 rows affected (0.02 sec)
#從庫延遲60秒。
(root@localhost)[(none)] start slave sql_thread;
Query OK, 0 rows affected (0.04 sec)
3、測試
主庫:
(root@localhost)[test] insert into tb1 values(3);
Query OK, 1 row affected (0.33 sec)
從庫:
(root@localhost)[(none)] show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.163.84.16
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1298
Relay_Log_File: dbrac17-relay-bin.000003
Relay_Log_Pos: 594
Relay_Master_Log_File: mysql-bin.000002
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: 1024
Relay_Log_Space: 1839
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: 4
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: 8416
Master_UUID: 3de828ce-354c-11e7-9f0b-0050568a4cf6
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 60
SQL_Remaining_Delay: 56
Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event
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
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
#SQL_Delay: 60表示延遲60秒。
#SQL_Remaining_Delay: 56表示還有56秒才開始應用日誌。
1分鐘後檢視:
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
Mysql透過指定從庫的master_delay選項來實現延遲應用。
1、安裝Mysql並配置主從
參考http://blog.itpub.net/28536251/viewspace-2138854/分別在兩節點安裝Mysql。
參考http://blog.itpub.net/28536251/viewspace-2138928/或者http://blog.itpub.net/28536251/viewspace-2139007/配置主從。
2、從庫配置延遲應用
(root@localhost)[(none)] stop slave sql_thread;
Query OK, 0 rows affected (0.15 sec)
(root@localhost)[(none)] change master to master_delay=60;
Query OK, 0 rows affected (0.02 sec)
#從庫延遲60秒。
(root@localhost)[(none)] start slave sql_thread;
Query OK, 0 rows affected (0.04 sec)
3、測試
主庫:
(root@localhost)[test] insert into tb1 values(3);
Query OK, 1 row affected (0.33 sec)
從庫:
(root@localhost)[(none)] show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.163.84.16
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1298
Relay_Log_File: dbrac17-relay-bin.000003
Relay_Log_Pos: 594
Relay_Master_Log_File: mysql-bin.000002
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: 1024
Relay_Log_Space: 1839
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: 4
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: 8416
Master_UUID: 3de828ce-354c-11e7-9f0b-0050568a4cf6
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 60
SQL_Remaining_Delay: 56
Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event
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
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
#SQL_Delay: 60表示延遲60秒。
#SQL_Remaining_Delay: 56表示還有56秒才開始應用日誌。
1分鐘後檢視:
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2139100/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 延遲從庫介紹MySql
- 從庫延遲案例分析
- MySQL 5.7 延遲複製配置MySql
- mysql主從延遲複製MySql
- 故障分析 | MySQL 異地從庫複製延遲案例一則MySql
- MySQL之 從複製延遲問題排查MySql
- MySQL主從複製延遲解決方案MySql
- 從Mysql slave system lock延遲說開去MySql
- MySQL主從資料庫同步延遲問題怎麼解決MySql資料庫
- Mysql 從庫如果有未提交的事務主庫ddl操作導致主從延遲MySql
- MySQL主從複製延遲原因及處理思路MySql
- mysql的主從複製資料延遲問題MySql
- mysql主從同步(4)-Slave延遲狀態監控MySql主從同步
- 主從延遲調優思路
- 我是如何找到 Express 應用延遲原因的Express
- 用機器學習對座席應答延遲的預測機器學習
- 面試官:我們們來聊一聊mysql主從延遲面試MySql
- MySQL主從延遲解決方法的歸納和總結MySql
- 記一次 MySQL 主從複製延遲的踩坑MySql
- 在Linux中,mysql 如何減少主從複製延遲?LinuxMySql
- 如何避免MYSQL主從延遲帶來的讀寫問題?MySql
- Mysql slave 延遲故障一列MySql
- MySQL Slave延遲很大優化方法MySql優化
- 第28節 從庫Seconds_Behind_Master延遲總結AST
- 影響MySQL主從延遲的幾個因素及解決方法MySql
- 【Mysql】Mysql負載過大,app訪問延遲MySql負載APP
- 高吞吐低延遲Java應用的垃圾回收優化Java優化
- [zt]Logical STANDBY日誌應用延遲案例一則
- 【MySQL】 效能優化之 延遲關聯MySql優化
- 【Mysql】Slave 延遲很大並且不動了MySql
- MongoDB從庫延遲讀取資料問題的解決思路MongoDB
- async-rdma:編寫高吞吐量、低延遲網路應用的Rust庫Rust
- MySQL 中讀寫分離資料延遲MySql
- 【MySQL】 效能最佳化之 延遲關聯MySql
- mysql之 誤用SECONDS_BEHIND_MASTER衡量MYSQL主備的延遲時間MySqlAST
- 技術分享 | 用圖資料庫來降低 MySQL 處理多層關係的延遲(一)資料庫MySql
- MySQL:雙主單寫 主庫偶爾出現大量延遲的原因MySql
- RabbitMQ延遲訊息的延遲極限是多少?MQ