溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

MYSQL并行復(fù)制怎么實(shí)現(xiàn)

發(fā)布時(shí)間:2021-08-26 00:21:18 來(lái)源:億速云 閱讀:159 作者:chen 欄目:MySQL數(shù)據(jù)庫(kù)

本篇內(nèi)容介紹了“MYSQL并行復(fù)制怎么實(shí)現(xiàn)”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

MySQL5.6開(kāi)始執(zhí)行基于庫(kù)級(jí)別的并行復(fù)制,MYSQL5.7支持基于表和行級(jí)別的并行復(fù)制(Enhanced Multi-Threaded Slave),這里主要是配置MYSQL5.7的基于組提交的并行復(fù)制。
一、環(huán)境描述

名稱    版本    備注
操作系統(tǒng)    RHEL6.5_X86_64    
數(shù)據(jù)庫(kù)    5.7.18-15   Percona二進(jìn)制版本
復(fù)制節(jié)點(diǎn)  10.26.7.129 node1 主節(jié)點(diǎn)
    10.26.7.142 node2 從節(jié)點(diǎn)

二、主要相關(guān)配置參數(shù)
node1節(jié)點(diǎn):
#replicate
server-id=1001
skip-slave-start = false
read-only = false
log-slave-updates = 1
expire_logs_days = 2
max_binlog_size = 1G
max_binlog_cache_size = 2G
log-bin = /home/mysql/mysql-bin
log-bin-index = /home/mysql/bin-index
sync_binlog = 1
binlog_format = row
log-slow-slave-statements = 1
max-relay-log-size = 1G
relay-log = /home/mysql/mysql-relay
relay-log-index = /home/mysql/relay-index
relay_log_recovery=ON
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE

node2節(jié)點(diǎn)
#replicate
server-id=1002
skip-slave-start = false
read-only = false
log-slave-updates = 1
expire_logs_days = 2
max_binlog_size = 1G
max_binlog_cache_size = 2G
log-bin = /home/mysql/mysql-bin
log-bin-index = /home/mysql/bin-index
sync_binlog = 1
binlog_format = row
log-slow-slave-statements = 1
max-relay-log-size = 1G
relay-log = /home/mysql/mysql-relay
relay-log-index = /home/mysql/relay-index
relay_log_recovery=ON
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE

#parallel slave
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=8

##slave-parallel-type
  DATABASE:默認(rèn)值,基于庫(kù)的并行復(fù)制方式
  LOGICAL_CLOCK:基于組提交的并行復(fù)制方式
三、數(shù)據(jù)庫(kù)啟動(dòng)并配置主從服務(wù)
數(shù)據(jù)庫(kù)啟動(dòng)略
node2從節(jié)點(diǎn)執(zhí)行下面命令:
change master to master_host='10.26.7.129',master_user='rpl_user',master_password='rpl_pass',master_port=3306,master_auto_position=1;
start slave;
show slave status \G

點(diǎn)擊(此處)折疊或打開(kāi)

  1. (root:localhost:Thu Jul 20 11:21:10 2017)[(none)]>show slave status \G

  2. *************************** 1. row ***************************

  3.                Slave_IO_State: Waiting for master to send event

  4.                   Master_Host: 10.26.7.129

  5.                   Master_User: rpl_user

  6.                   Master_Port: 3306

  7.                 Connect_Retry: 60

  8.               Master_Log_File: mysql-bin.000006

  9.           Read_Master_Log_Pos: 190

  10.                Relay_Log_File: mysql-relay.000002

  11.                 Relay_Log_Pos: 355

  12.         Relay_Master_Log_File: mysql-bin.000006

  13.              Slave_IO_Running: Yes

  14.             Slave_SQL_Running: Yes

  15.               Replicate_Do_DB:

  16.           Replicate_Ignore_DB:

  17.            Replicate_Do_Table:

  18.        Replicate_Ignore_Table:

  19.       Replicate_Wild_Do_Table:

  20.   Replicate_Wild_Ignore_Table:

  21.                    Last_Errno: 0

  22.                    Last_Error:

  23.                  Skip_Counter: 0

  24.           Exec_Master_Log_Pos: 190

  25.               Relay_Log_Space: 550

  26.               Until_Condition: None

  27.                Until_Log_File:

  28.                 Until_Log_Pos: 0

  29.            Master_SSL_Allowed: No

  30.            Master_SSL_CA_File:

  31.            Master_SSL_CA_Path:

  32.               Master_SSL_Cert:

  33.             Master_SSL_Cipher:

  34.                Master_SSL_Key:

  35.         Seconds_Behind_Master: 0

  36. Master_SSL_Verify_Server_Cert: No

  37.                 Last_IO_Errno: 0

  38.                 Last_IO_Error:

  39.                Last_SQL_Errno: 0

  40.                Last_SQL_Error:

  41.   Replicate_Ignore_Server_Ids:

  42.              Master_Server_Id: 1001

  43.                   Master_UUID: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec

  44.              Master_Info_File: mysql.slave_master_info

  45.                     SQL_Delay: 0

  46.           SQL_Remaining_Delay: NULL

  47.       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

  48.            Master_Retry_Count: 86400

  49.                   Master_Bind:

  50.       Last_IO_Error_Timestamp:

  51.      Last_SQL_Error_Timestamp:

  52.                Master_SSL_Crl:

  53.            Master_SSL_Crlpath:

  54.            Retrieved_Gtid_Set:

  55.             Executed_Gtid_Set: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec:1-28,

  56. 35e38786-66bb-11e7-bcc3-b8ca3a6a61a4:1

  57.                 Auto_Position: 1

  58.          Replicate_Rewrite_DB:

  59.                  Channel_Name:

  60.            Master_TLS_Version:

  61. 1 row in set (0.00 sec)

四、數(shù)據(jù)庫(kù)多線程復(fù)制測(cè)試、狀態(tài)監(jiān)控
node1:

點(diǎn)擊(此處)折疊或打開(kāi)

  1. (root:localhost:Thu Jul 20 11:23:05 2017)[(none)]>drop database db01;

  2. Query OK, 1 row affected (0.02 sec)


  3. (root:localhost:Thu Jul 20 11:23:17 2017)[(none)]>use dbtest;

  4. Database changed

  5. (root:localhost:Thu Jul 20 11:23:22 2017)[dbtest]>create table t(id int);

  6. Query OK, 0 rows affected (0.01 sec)


  7. (root:localhost:Thu Jul 20 11:25:03 2017)[dbtest]>insert into t values(10);

  8. Query OK, 1 row affected (0.01 sec)

node2:

點(diǎn)擊(此處)折疊或打開(kāi)

  1. (root:localhost:Thu Jul 20 11:23:12 2017)[(none)]>show databases;

  2. +--------------------+

  3. | Database |

  4. +--------------------+

  5. | information_schema |

  6. | dbtest |

  7. | mysql |

  8. | performance_schema |

  9. | sys |

  10. +--------------------+

  11. 5 rows in set (0.00 sec)


  12. (root:localhost:Thu Jul 20 11:25:12 2017)[(none)]>use dbtest;

  13. Database changed

  14. (root:localhost:Thu Jul 20 11:25:15 2017)[dbtest]>select * from t;

  15. +------+

  16. | id |

  17. +------+

  18. | 10 |

  19. +------+

  20. 1 row in set (0.00 sec)

  21. (root:localhost:Thu Jul 20 11:25:20 2017)[dbtest]>show slave status \G

  22. *************************** 1. row ***************************

  23.                Slave_IO_State: Waiting for master to send event

  24.                   Master_Host: 10.26.7.129

  25.                   Master_User: rpl_user

  26.                   Master_Port: 3306

  27.                 Connect_Retry: 60

  28.               Master_Log_File: mysql-bin.000006

  29.           Read_Master_Log_Pos: 732

  30.                Relay_Log_File: mysql-relay.000002

  31.                 Relay_Log_Pos: 897

  32.         Relay_Master_Log_File: mysql-bin.000006

  33.              Slave_IO_Running: Yes

  34.             Slave_SQL_Running: Yes

  35.               Replicate_Do_DB:

  36.           Replicate_Ignore_DB:

  37.            Replicate_Do_Table:

  38.        Replicate_Ignore_Table:

  39.       Replicate_Wild_Do_Table:

  40.   Replicate_Wild_Ignore_Table:

  41.                    Last_Errno: 0

  42.                    Last_Error:

  43.                  Skip_Counter: 0

  44.           Exec_Master_Log_Pos: 732

  45.               Relay_Log_Space: 1092

  46.               Until_Condition: None

  47.                Until_Log_File:

  48.                 Until_Log_Pos: 0

  49.            Master_SSL_Allowed: No

  50.            Master_SSL_CA_File:

  51.            Master_SSL_CA_Path:

  52.               Master_SSL_Cert:

  53.             Master_SSL_Cipher:

  54.                Master_SSL_Key:

  55.         Seconds_Behind_Master: 0

  56. Master_SSL_Verify_Server_Cert: No

  57.                 Last_IO_Errno: 0

  58.                 Last_IO_Error:

  59.                Last_SQL_Errno: 0

  60.                Last_SQL_Error:

  61.   Replicate_Ignore_Server_Ids:

  62.              Master_Server_Id: 1001

  63.                   Master_UUID: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec

  64.              Master_Info_File: mysql.slave_master_info

  65.                     SQL_Delay: 0

  66.           SQL_Remaining_Delay: NULL

  67.       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

  68.            Master_Retry_Count: 86400

  69.                   Master_Bind:

  70.       Last_IO_Error_Timestamp:

  71.      Last_SQL_Error_Timestamp:

  72.                Master_SSL_Crl:

  73.            Master_SSL_Crlpath:

  74.            Retrieved_Gtid_Set: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec:29-31

  75.             Executed_Gtid_Set: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec:1-31,

  76. 35e38786-66bb-11e7-bcc3-b8ca3a6a61a4:1

  77.                 Auto_Position: 1

  78.          Replicate_Rewrite_DB:

  79.                  Channel_Name:

  80.            Master_TLS_Version:

  81. 1 row in set (0.00 sec)

(root:localhost:Thu Jul 20 11:27:34 2017)[information_schema]>use performance_schema;
Database changed
(root:localhost:Thu Jul 20 11:27:38 2017)[performance_schema]>show tables like '%replica%';    
+-------------------------------------------+
| Tables_in_performance_schema (%replica%)  |
+-------------------------------------------+
| replication_applier_configuration         |
| replication_applier_status                |
| replication_applier_status_by_coordinator |
| replication_applier_status_by_worker      |
| replication_connection_configuration      |
| replication_connection_status             |
| replication_group_member_stats            |
| replication_group_members                 |
+-------------------------------------------+
8 rows in set (0.00 sec)

多線復(fù)制狀態(tài)監(jiān)控:
select * from  replication_applier_status_by_coordinator     ;
select * from   replication_applier_status_by_worker ;

“MYSQL并行復(fù)制怎么實(shí)現(xiàn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI