MySQL半同步复制rpl 您所在的位置:网站首页 sync_master_info MySQL半同步复制rpl

MySQL半同步复制rpl

2024-06-13 00:16| 来源: 网络整理| 查看: 265

测试环境:mysql5.7.26  一主两从

查看主库状态:

mysql> show status like 'Rpl_semi_sync_master_status'; +-----------------------------+-------+ | Variable_name               | Value | +-----------------------------+-------+ | Rpl_semi_sync_master_status | ON    | +-----------------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'rpl_semi_sync_master_timeout'; +------------------------------+-------+ | Variable_name                | Value | +------------------------------+-------+ | rpl_semi_sync_master_timeout | 10000 | +------------------------------+-------+ 1 row in set (0.00 sec)

查看从库状态:

从库一

mysql> show status like 'Rpl_semi_sync_slave_status'; +----------------------------+-------+ | Variable_name              | Value | +----------------------------+-------+ | Rpl_semi_sync_slave_status | ON    | +----------------------------+-------+ 1 row in set (0.00 sec) mysql> show slave status \G *************************** 1. row ***************************                Slave_IO_State: Waiting for master to send event                   Master_Host: 172.16.254.163                   Master_User: repl                   Master_Port: 3307                 Connect_Retry: 60               Master_Log_File: mysql-bin.000012           Read_Master_Log_Pos: 154                Relay_Log_File: 163-3308-relay-bin.000005                 Relay_Log_Pos: 367         Relay_Master_Log_File: mysql-bin.000012              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: 154               Relay_Log_Space: 743               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: 1633307                   Master_UUID: badf10a9-e13f-11ea-ac1b-1866daf6f710              Master_Info_File: /mysql/mysql3308/data/master.info                     SQL_Delay: 0           SQL_Remaining_Delay: NULL       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates            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)

从库二

show status like 'Rpl_semi_sync_slave_status'; +----------------------------+-------+ | Variable_name              | Value | +----------------------------+-------+ | Rpl_semi_sync_slave_status | ON    | +----------------------------+-------+ 1 row in set (0.00 sec) mysql> show slave status \G *************************** 1. row ***************************                Slave_IO_State: Waiting for master to send event                   Master_Host: 172.16.254.163                   Master_User: repl                   Master_Port: 3307                 Connect_Retry: 60               Master_Log_File: mysql-bin.000012           Read_Master_Log_Pos: 154                Relay_Log_File: 163-3309-relay-bin.000005                 Relay_Log_Pos: 367         Relay_Master_Log_File: mysql-bin.000012              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: 154               Relay_Log_Space: 743               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: 1633307                   Master_UUID: badf10a9-e13f-11ea-ac1b-1866daf6f710              Master_Info_File: /mysql/mysql3309/data/master.info                     SQL_Delay: 0           SQL_Remaining_Delay: NULL       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates            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)

主库创建测试表:

mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> create table t1(id int); Query OK, 0 rows affected (0.01 sec)

可以看到很快就行创建完毕。

此时关闭从库一的复制

mysql> stop slave; Query OK, 0 rows affected (0.00 sec)

主库插入一条记录

mysql> insert into t1(id) values(1); Query OK, 1 row affected (0.00 sec)

依然很快就能插入成功。

此时把从库二的复制也关闭

mysql> stop slave; Query OK, 0 rows affected (0.00 sec)

再次往测试表t1插入数据

mysql> insert into t1(id) values(1); Query OK, 1 row affected (10.00 sec) mysql> insert into t1(id) values(1); Query OK, 1 row affected (0.00 sec) mysql> insert into t1(id) values(1); Query OK, 1 row affected (0.00 sec)

可以看到第一次insert用了10s,这和rpl_semi_sync_master_timeout=10000相吻合。

此时查看主库状态:

mysql> show status like 'Rpl_semi_sync_master_status'; +-----------------------------+-------+ | Variable_name               | Value | +-----------------------------+-------+ | Rpl_semi_sync_master_status | OFF   | +-----------------------------+-------+ 1 row in set (0.00 sec)

半同步复制已经关闭,降级为了异步复制。

       主库在执行完客户端提交的事务后不是立刻返回给客户端,而是等待至少一个从库接收到并写到relay log中才返回给客户端。相对于异步复制,半同步复制提高了数据的安全性,同时它也造成了一定程度的延迟,这个延迟最少是一个TCP/IP往返的时间。所以, 半同步复制最好在低延时的网络中使用。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有