MySQL 5.7.9主从及Enhanced Multi-Threaded Slave配置

1.master/slave hosts文件

root login

hosts(master/slave)

127.0.0.1 localhost

10.8.1.5 mdb01

10.8.1.6 sdb01

cp soft/mysql-5.7.9/support-files/my-default.cnf /etc/my.cnf

2.master server-id

root login

vi /etc/my.cnf

[mysqld]

log-bin=mysql-bin(DATADIR/mysql-bin)

server-id=1

3.Slave server-id

vi /etc/my.cnf

[mysqld]

server-id=2

4.master 复制用户,锁表禁止插入

mysql> CREATE USER ‘repl‘@‘%‘ IDENTIFIED BY ‘repl‘;

Query OK, 0 rows affected (0.18 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO ‘repl‘@‘%‘;

Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.09 sec)

锁定表

mysql> FLUSH TABLES WITH READ LOCK;

Query OK, 0 rows affected (0.44 sec)

在master一个不同的session

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000006 |      154 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql>

5.如果存在同步主从数据

master

mysql> UNLOCK TABLES;

6.Slave 设置日志开始复制位置

mysql> CHANGE MASTER TO

->         MASTER_HOST=‘mdb01‘,

->         MASTER_USER=‘repl‘,

->         MASTER_PASSWORD=‘repl‘,

->         MASTER_LOG_FILE=‘mysql-bin.000006‘,

->         MASTER_LOG_POS=154;

Query OK, 0 rows affected, 2 warnings (0.09 sec)

7.启动slave

mysql> START SLAVE;

Query OK, 0 rows affected (0.07 sec)

8.检查slave状态

mysql> show slave status\G;

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

Slave_IO_State: Waiting for master to send event

Master_Host: mdb01

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000006

Read_Master_Log_Pos: 319

Relay_Log_File: sdb01-relay-bin.000003

Relay_Log_Pos: 485

Relay_Master_Log_File: mysql-bin.000006

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: 319

Relay_Log_Space: 692

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: 1

Master_UUID: 42ad8740-7e88-11e5-83de-000c29270868

Master_Info_File: /opt/mysql/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:

1 row in set (0.00 sec)

ERROR:

No query specified

mysql>

配置可能遇到的问题:

主从如果是同一个虚拟机复制生成的两台auto.cnf文件中server-uuid相同,Slave_IO_Running: Null 进程可能无法启动。

error日志提示:

[ERROR] Slave I/O for channel ‘‘: Fatal error: The slave I/O thread stops because master and slave hav

e equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code: 1593

需要修改其中任何一个MySQL数据库DataDir目录下的auto.cnf文件中修改为不同值,然后停止slave后,重新启动MySQL服务,然后再启动Slave便正常运行了。

[auto]

server-uuid=42ad8740-7e88-11e5-83de-000c29270869

9、主从测试

1).master

mysql> create database testdb;

mysql> use testdb;

mysql> create table user (

-> uid int auto_increment,

->    data json,primary key(uid)

-> );

Query OK, 0 rows affected (0.27 sec)

mysql> insert into user values (NULL,‘{"name":"David","mail":"[email protected]","address":"Shangahai"}‘);

Query OK, 1 row affected (0.64 sec)

mysql> insert into user values (NULL,‘{"name":"Amy","mail":"[email protected]"}‘);

Query OK, 1 row affected (0.14 sec)

mysql> select data->"$.name" from user;

+----------------+

| data->"$.name" |

+----------------+

| "David"        |

| "Amy"          |

+----------------+

2 rows in set (0.16 sec)

mysql>

2).slave

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

| testdb             |

+--------------------+

5 rows in set (0.00 sec)

mysql> use testdb

Database changed

mysql> show tables;

+------------------+

| Tables_in_testdb |

+------------------+

| user             |

+------------------+

1 row in set (0.00 sec)

mysql> desc user;

+-------+---------+------+-----+---------+----------------+

| Field | Type    | Null | Key | Default | Extra          |

+-------+---------+------+-----+---------+----------------+

| uid   | int(11) | NO   | PRI | NULL    | auto_increment |

| data  | json    | YES  |     | NULL    |                |

+-------+---------+------+-----+---------+----------------+

2 rows in set (0.01 sec)

mysql> SHOW CREATE TABLE user\G;

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

Table: user

Create Table: CREATE TABLE `user` (

`uid` int(11) NOT NULL AUTO_INCREMENT,

`data` json DEFAULT NULL,

PRIMARY KEY (`uid`)

) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

ERROR:

No query specified

mysql> select data ->"$.name" from user;

+-----------------+

| data ->"$.name" |

+-----------------+

| "David"         |

| "Amy"           |

+-----------------+

2 rows in set (0.03 sec)

mysql>

10.Slave并行复制配置

Enhanced Multi-Threaded Slave配置,配置后重启MySQL服务器。

说了这么多,要开启enhanced multi-threaded slave其实很简单,只需根据如下设置:

# slave

slave-parallel-type=LOGICAL_CLOCK

slave-parallel-workers=16

master_info_repository=TABLE

relay_log_info_repository=TABLE

relay_log_recovery=ON

并行复制监控

复制的监控依旧可以通过SHOW SLAVE STATUS\G,但是MySQL 5.7在performance_schema架构下多了以下这些元数据表,用户可以更细力度的进行监控:

mysql> show tables like ‘replication%‘;

+---------------------------------------------+

| Tables_in_performance_schema (replication%) |

+---------------------------------------------+

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

slave状态:

mysql> SHOW SLAVE STATUS\G;

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

Slave_IO_State: Waiting for master to send event

Master_Host: mdb01

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000006

Read_Master_Log_Pos: 1196

Relay_Log_File: sdb01-relay-bin.000005

Relay_Log_Pos: 320

Relay_Master_Log_File: mysql-bin.000006

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: 1196

Relay_Log_Space: 527

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: 1

Master_UUID: 42ad8740-7e88-11e5-83de-000c29270868

Master_Info_File: mysql.slave_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:

1 row in set (0.00 sec)

ERROR:

No query specified

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

| testdb             |

+--------------------+

5 rows in set (0.01 sec)

mysql> use performance_schema

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> show tables like ‘replication%‘;

+---------------------------------------------+

| Tables_in_performance_schema (replication%) |

+---------------------------------------------+

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

mysql>

参考文献

http://www.innomysql.net/article/16317.html

时间: 2024-10-18 21:44:32

MySQL 5.7.9主从及Enhanced Multi-Threaded Slave配置的相关文章

MySQL数据库多实例主从同步

本文主要介绍单台服务器MySQL数据库多实例的主从同步,一般常规做主从复制主从服务器在不同的机器上,并且监听端口均为默认的3306端口.一.环境介绍 操作系统:CentOS 6.5 数据库版本:MySQL 5.5.32 主库主机名称:mysql-master(172.18.10.222:3306) 从库主机名称:mysql-slave(172.18.10.222:3307) 二.主从同步原理介绍  简单描述主从复制原理: 1.在Slave服务器命令行执行start slave,开启主从复制开关

MYSQL在centos上主从及读写分离的配置

 一:MYSQL主从配置   1.1 部署环境 主(master_mysql): 192.168.1.200     OS:CentOS 6.5   从(slave_mysql):   192.168.1.201      OS:CentOS 6.5  1.2 安装mysql 主和从:   yum install mysql-server  1.3 配置           1.3.1 主配置(master_mysql配置) vim /etc/my.cnf server-id=200 #设置主服

缓解MySQL写入压力和主从延迟的尝试

缓解MySQL写入压力和主从延迟的尝试 http://mp.weixin.qq.com/s?__biz=MzA5Njg5ODMzMg==&mid=208512935&idx=1&sn=a605bb3b2f944f7fdce820b940e0888b&scene=2&from=timeline&isappinstalled=0#rd 最近单位需要用MySQL存放大量的日志数据.写入压力很大,并且有很大的主从延迟. 具体环境如下MySQL 5.6.14服务器(单

mysql 5.6.33主从+主主

1 实验环境 # cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) A主机:master IP:192.168.1.138 MYSQL:# mysql -Vmysql  Ver 14.14 Distrib 5.6.33 B主机:slave  IP:192.168.1.9   MYSQL:# mysql -Vmysql  Ver 14.14 Distrib 5.6.33 注意:mysql数据库的版本,两个数据库版本要相同,或者

mysql集群(主从)

本文主要记录mysql 主从配置. 经典的原理图 0.环境: 采用阿里云ECS服务器,同区同配置,操作系统为ubuntus 14 64位,服务器如下: 服务器A: 内网IP: 10.44.94.219 服务器B: 内网IP: 10.44.94.97 安装mysql环境,命令如下: sudo apt-get update sudo apt-get install mysql-server mysql-client 1 Master 配置: 创建复制账号: GRANT REPLICATION SLA

Mysql、MariaDB 新型主从集群配置GTID

前文谢了<Mysql.MariaDB 传统主从集群配置>,该技术已经非常成熟.从Mysql5.6和MariaDB10.0开始,有了新型的主从方案GTID,不过这两个系统到这个版本出现了分支,具体实现已经不同,配置方法也不同,下文分别讲述. MariaDB: 我用的版本还是10.1版,目前该版本还不是稳定版,但不影响测试.先部署部署好两个数据库实例,参见http://bangbangba.blog.51cto.com/3180873/1701857 直到创建好复制用户. 我们这里的由于是新创建的

【转】双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计

架构简介 前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构.此架构主要是由keepalived实现双机高可用,维护了一个外网VIP,一个内网VIP.正常情况时,外网VIP和内网VIP都绑定在server1服务器,web请求发送到server1的nginx,nginx对于静态资源请求就直接在本机检索并返回,对于php的动态请求,则负载均衡到server1和server2.对于SQ

mysql真实环境搭建主从

 mysql真实环境搭建主从 防伪码:人之所以能,是相信能. 前言:当今数据库有oracle mysql  SQL Server ACCESS 等等很多种,今天我们来真实环境搭建mysql主从.先说一下四种数据库的区别: 1.四种数据库的区别: ACCESS:功能相对不是那么强大,主要是开发单机版软件中经常用到. SQL Server:是目前应用比较广泛和普遍的一款数据库,是数据库发展的一个里程碑. MySQL:是一个开源的关系数据库管理系统,有快速.可靠和易于使用的特点:MySQL服务器工作在

MySQL的3节点主从同步复制方案

上篇文章<为什么要对MySQL做主从同步复制>我们说明了MySQL主从同步的作用,主从同步的原理和主从同步的缺点.下面我们介绍下3节点中:2个节点互为主从,1个节点作为前2个节点的从,用于实现MySQL5.6的3节点主从同步复制方案. 主要步骤如下: 1.配置MasterA端同步复制时所需要的选项 2.在MasterA主库上创建同步复制时的用户并授权 3.MasterA主库锁表 4.记录MasterA主库的binlog以及pos位置节点 5.导出MasterA主库m_s_rep数据库 6.配置