在作MySQL主從半同步以前先作主從複製mysql
1、部署MySQL主從半同步複製sql
半同步複製支持多種插件:/usr/lib64/mysql/plugin/*數據庫
半同步複製插件:ide
semisync_master.sospa
semisync_slave.so插件
[root@localhost ~]# rpm -ql mariadb-server | grep semisync
/usr/lib64/mysql/plugin/semisync_master.so
/usr/lib64/mysql/plugin/semisync_slave.so線程
一、1十一、112進入mysql查看插件是否安裝3d
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.41-MariaDB-log MariaDB Serverorm
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.server
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show plugins;
二、若是沒有安裝,則先在主節點安裝並啓用插件:
MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show plugins;
MariaDB [(none)]> show global variables like '%semi%';
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| rpl_semi_sync_master_enabled | OFF |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_no_slave | ON |
+------------------------------------+-------+
4 rows in set (0.00 sec)
MariaDB [(none)]> set @@global.rpl_semi_sync_master_enabled=ON;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show global variables like '%semi%';
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_no_slave | ON |
+------------------------------------+-------+
4 rows in set (0.00 sec)
三、在從節點安裝並啓用插件:
MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show plugins;
MariaDB [(none)]> show global variables like '%semi%';
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| rpl_semi_sync_master_enabled | OFF |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_no_slave | ON |
+------------------------------------+-------+
4 rows in set (0.00 sec)
MariaDB [(none)]> set @@global.rpl_semi_sync_master_enabled=ON;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show global variables like '%semi%';
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_no_slave | ON |
+------------------------------------+-------+
4 rows in set (0.00 sec)
四、先查看主節點,而後從節點啓動IO線程,在查看主節點
MariaDB [(none)]> show global status like '%semi%';
從節點啓動IO線程:
MariaDB [(none)]> stop slave IO_THREAD;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> start slave IO_THREAD;
Query OK, 0 rows affected (0.00 sec)
主節點:
五、在主節點爲事先建立的用戶進行主從複製受權:
MariaDB [(none)]> grant replication slave on *.* to 'myslave'@'192.168.200.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000004 | 931 | | |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
六、從節點:
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> CHANGE MASTER TO
-> MASTER_HOST='192.168.200.111',
-> MASTER_USER='myslave',
-> MASTER_PASSWORD='123456',
-> MASTER_LOG_FILE='mysql-binlog.000004',
-> MASTER_LOG_POS=931;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
七、在主節點建立數據庫mydb
MariaDB [(none)]>create database nydb character set 'utf8';
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| performance_schema |
| test |
| test01 |
| test02 |
+--------------------+
7 rows in set (0.01 sec)
在從節點查看數據庫是否複製成功:
發現數據庫mydb複製成功
在主節點進行數據操做:
MariaDB [(none)]> use mydb
Database changed
MariaDB [mydb]> create table tbl1 (id int,name varchar(100));
Query OK, 0 rows affected (0.03 sec)
主節點繼續操做:
MariaDB [mydb]> insert into tbl1 values (1,'tom');
Query OK, 1 row affected (0.01 sec)
咱們發現從節點的數據都在變化: