首页 > 代码库 > mysql主从复制异步半同步实例

mysql主从复制异步半同步实例

  1. 建立mysql的复制

    node1:

    mysql> show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000003 |      120 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    1 row in set (0.00 sec)

    mysql>

     

    node2:

    mysql> change master to master_host=‘192.168.56.102‘,master_user=‘qwer‘,master_password=‘system‘,master_log_file=‘mysql-bin.000003‘,master_log_pos=120,master_port=3306;
    Query OK, 0 rows affected, 2 warnings (0.04 sec)

    mysql> start slave;
    Query OK, 0 rows affected (0.03 sec)

    mysql> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.56.102
                      Master_User: qwer
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000003
              Read_Master_Log_Pos: 120
                   Relay_Log_File: node2-relay-bin.000002
                    Relay_Log_Pos: 283
            Relay_Master_Log_File: mysql-bin.000003
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
                 Replicate_Do_DB: tongs

2.加载插件

     node1:

     mysql> install plugin rpl_semi_sync_master soname ‘semisync_master.so‘;            

     mysql> set global rpl_semi_sync_master_enabled=1;          --开启半同步
     mysql> set global rpl_semi_sync_master_timeout=1000;      --半同步1000毫秒

 

     node2:

     mysql> install plugin rpl_semi_sync_slave soname ‘semisync_slave.so‘;
     mysql> set  global rpl_semi_sync_slave_enabled=1;

3.查看状态

     node1: 

     mysql> show variables like ‘%rpl_%‘;
     +-------------------------------------------+------------+
     | Variable_name                             | Value      |
     +-------------------------------------------+------------+
     | rpl_semi_sync_master_enabled              | ON         |
     | rpl_semi_sync_master_timeout              | 1000       |
     | rpl_semi_sync_master_trace_level          | 32         |
     | rpl_semi_sync_master_wait_for_slave_count | 1          |
     | rpl_semi_sync_master_wait_no_slave        | ON         |
     | rpl_semi_sync_master_wait_point           | AFTER_SYNC |
     | rpl_stop_slave_timeout                    | 31536000   | 
      +-------------------------------------------+------------+
     7 rows in set (0.00 sec)

     mysql>

    

     node2:

     mysql> show variables like ‘%rpl_%‘;
     +---------------------------------+----------+
     | Variable_name                   | Value    |
     +---------------------------------+----------+
     | rpl_semi_sync_slave_enabled     | ON       |
     | rpl_semi_sync_slave_trace_level | 32       |
     | rpl_stop_slave_timeout          | 31536000 |
      +---------------------------------+----------+
     3 rows in set (0.00 sec)

     mysql>

 

本文出自 “一起走过的日子” 博客,谢绝转载!

mysql主从复制异步半同步实例