2019.10.17 MySQL半同步复制

在作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)

咱们发现从节点的数据都在变化:

相关文章
相关标签/搜索