mysql5.7使用gtid模式搭建主从复制架构
一、架构
两台mysql服务器做一主一从,172.28.18.69(主) 172.28.18.78(从)
二、分别编译安装mysql5.7
1、下载mysql5.7.26源码包
[root@server- /]# mkdir /usr/local/src/mysql-5.7.-src
[root@server-]# cd /usr/local/src/mysql-5.7.-src/
[root@server- mysql-5.7.-src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz
2、添加mysql用户和组
[root@server- mysql-5.7.-src]# useradd mysql
[root@server- mysql-5.7.-src]# id mysql
uid=(mysql) gid=(mysql) 组=(mysql)
3、设置mysql用户密码
[root@server- mysql-5.7.-src]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
4、新建mysql相关目录,并赋权限给mysql用户
[root@server- mysql-5.7.-src]# mkdir /home/mysql-5.7.
[root@server- mysql-5.7.-src]# mkdir /home/mysql-5.7./data
[root@server- mysql-5.7.-src]# mkdir /home/mysql-5.7./log
[root@server- mysql-5.7.-src]# mkdir -p /home/mysql-5.7./run
[root@server- home]# chown -R mysql:mysql mysql-5.7./
[root@server- home]# cd mysql-5.7./
[root@server- mysql-5.7.]# ll
总用量
drwxr-xr-x mysql mysql 5月 : data
drwxr-xr-x mysql mysql 5月 : log
drwxr-xr-x mysql mysql 5月 : run
5、安装依赖包
[root@server-]# yum install cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl automake autoconf make libtool bison-devel libaio-devel -y
6、安装boost
MySQL5.7.24要求boost的版本是1.59,更高版本的不适用MySQL5.7.24
[root@server-1 /]# cd /usr/local/src/
[root@server-1 src]# wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
[root@server-1 src]# tar -zxvf boost_1_59_0.tar.gz
[root@server- src]# mv boost_1_59_0 /usr/local/
7、编译安装
[root@server- /]# cd /usr/local/src/mysql-5.7.-src/
[root@server- mysql-5.7.-src]# tar -zxvf mysql-5.7..tar.gz
[root@server- mysql-5.7.]# cd mysql-5.7.
[root@server- mysql-5.7.]# cmake -DCMAKE_INSTALL_PREFIX=/home/mysql-5.7. -DINSTALL_DATADIR=/home/mysql-5.7./data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=yes -DWITH_EMBEDDED_SERVER= -DENABLED_LOCAL_INFILE= -DWITH_MYISAM_STORAGE_ENGINE= -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DWITH_FEDERATED_STORAGE_ENGINE= -DWITH_PARTITION_STORAGE_ENGINE= -DMYSQL_UNIX_ADDR=/home/mysql-5.7./run/mysql.sock -DMYSQL_TCP_PORT= -DENABLED_LOCAL_INFILE= -DSYSCONFDIR=/etc -DWITH_READLINE=on -DWITH_BOOST=/usr/local/boost_1_59_0
如果中途出现错误,则根据错误信息去查找问题,再次编译的时候,一定需要删除mysql-5.7.26下的CMakeCache.txt这个文件,清空缓存才能再次编译,否则还是跟上次一样出现错误。
最后出现
CMake Warning:
Manually-specified variables were not used by the project: INSTALL_DATADIR
WITH_READLINE -- Build files have been written to: /usr/local/src/mysql-5.7.-src/mysql-5.7.
编译成功,再执行
[root@server- mysql-5.7.]# make && make install
最后出现
-- Installing: /home/mysql-5.7./mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /home/mysql-5.7./support-files/mysqld_multi.server
-- Installing: /home/mysql-5.7./support-files/mysql-log-rotate
-- Installing: /home/mysql-5.7./support-files/magic
-- Installing: /home/mysql-5.7./share/aclocal/mysql.m4
-- Installing: /home/mysql-5.7./support-files/mysql.server
8、编写配置文件my.cnf
[root@server- mysql-5.7.]# vim /etc/my.cnf
[mysqld]
bsedir=/home/mysql-5.7.
datadir=/home/mysql-5.7./data
socket=/home/mysql-5.7./run/mysql.sock
user=mysql
symbolic-links=
[mysqld_safe]
log-error=/home/mysql-5.7./log/mysqld.log
pid-file=/home/mysql-5.7./run/mysqld.pid
9、配置环境变量
[root@server- mysql-5.7.]# vim /etc/profile
在文件末尾加上
PATH=$PATH:/home/mysql-5.7./bin/
[root@server- mysql-5.7.]# source /etc/profile
10、初始化系统数据库
[root@server- /]# mysqld --initialize --user=mysql --basedir=/home/mysql-5.7./ --datadir=/home/mysql-5.7./data/
[root@server- /]#
没有报错,查看日志中的初始密码
[root@server- /]# cat /home/mysql-5.7./log/mysqld.log |grep password
--04T01::.224507Z [Note] A temporary password is generated for root@localhost: dyB8iUq<EaK;
11、启动数据库
[root@server- /]# mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
--04T02::.566664Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'.
--04T02::.629556Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7./data
12、启动客户端,输入初始密码登录数据库
[root@server- ~]# mysql -uroot -p
13、修改密码
mysql> set PASSWORD=PASSWORD('xxxxxxx');
mysql> alter user 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, rows affected (0.00 sec)
mysql> flush privileges;
Query OK, rows affected (0.00 sec)
退出,重新登录
[root@server- ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
三、配置主从配置
1、主库172.28.18.69配置文件
[mysqld]
basedir=/home/mysql-5.7.
datadir=/home/mysql-5.7./data
socket=/home/mysql-5.7./run/mysql.sock
user=mysql
symbolic-links=
server_id=
gtid_mode=on #开启gtid模式
enforce_gtid_consistency=on #强制gtid一致性
log-bin=master #开启二进制日志
binlog_format=row [mysqld_safe]
log-error=/home/mysql-5.7./log/mysqld.log
pid-file=/home/mysql-5.7./run/mysqld.pid
重启mysql,并登录mysql
[root@server- /]# mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
[]
[root@server- /]# --04T02::.501598Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'.
--04T02::.554499Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7./data
^C
[root@server- /]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
查询主库状态
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| master. | | | | |
+---------------+----------+--------------+------------------+-------------------+
多了一个Executed_Gtid_Set
查询gitd相关变量
mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-----------+
rows in set (0.00 sec)
2、主库上创建repl账号
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'xxxxxx';
Query OK, rows affected, warning (0.02 sec)
3从库配置文件
[mysqld]
basedir=/home/mysql-5.7.
datadir=/home/mysql-5.7./data
socket=/home/mysql-5.7./run/mysql.sock
user=mysql
symbolic-links=
server_id=
gtid_mode=on #开启gtid模式
enforce_gtid_consistency=on
log-bin=salve
binlog_format=row [mysqld_safe]
log-error=/home/mysql-5.7./log/mysqld.log
pid-file=/home/mysql-5.7./run/mysqld.pid
重启mysql
[root@server- log]# mysqld_safe --defaults-file=/etc/mysql/my.cnf &
[]
[root@server- log]# --04T02::.867996Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'.
--04T02::.899183Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7./data
登录mysql,从库执行以下命令
mysql> change master to master_host='172.28.18.69' ,master_user='repl',master_password='xxxxxx',master_auto_position=;
Query OK, rows affected, warnings (0.30 sec) mysql> start slave;
Query OK, rows affected (0.02 sec)
查看从库状态
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.28.18.69
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: master.
Read_Master_Log_Pos:
Relay_Log_File: server--relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: ee3e292b-866b-11e9-9df8-14feb5dc2c77
Master_Info_File: /home/mysql-5.7./data/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: ee3e292b-866b-11e9-9df8-14feb5dc2c77:
Executed_Gtid_Set: 520b8b86--11e9--90b11c15be09:-,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)
成功
mysql> mysql> show variables like '%gtid%';
+----------------------------------+----------------------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | ee3e292b-866b-11e9-9df8-14feb5dc2c77: |
| session_track_gtids | OFF |
+----------------------------------+----------------------------------------+
测试
主库新建test库和test表,插入一条记录
mysql> create database test;
Query OK, row affected (0.02 sec) mysql> use test;
Database changed
mysql> create table test(id int ,name varchar());
Query OK, rows affected (0.14 sec) mysql> insert into test values(,'aaaaa');
Query OK, row affected (0.05 sec) mysql> select * from test;
+------+-------+
| id | name |
+------+-------+
| | aaaaa |
+------+-------+
row in set (0.00 sec)
在从库上查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
rows 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> select * from test;
+------+-------+
| id | name |
+------+-------+
| | aaaaa |
+------+-------+
row in set (0.00 sec)
数据同步成功。
mysql5.7使用gtid模式搭建主从复制架构的更多相关文章
- mysql5.7基于gtid进行搭建主从复制过程
gtid_mode = onenforce-gtid-consistency = onskip_name_resolve # 去掉域名解析二进制日志必须开启,且格式为ROWserver-id必须配置成 ...
- 基于GTID模式MySQL主从复制
基于GTID模式MySQL主从复制 GTID复制原理:基于GTID的复制是MySQL 5.6后新增的复制方式GTID (global transaction identifier) 即全局事务ID, ...
- MySQL传统点位复制在线转为GTID模式复制
1. GTID优缺点 MySQL传统点位复制在5.7版本前是主要的主从复制模式,而随着MySQL5.6版本引入GTID,并且MySQL5.7进行各方面的优化以后,在mySQL5.7(尤其是MySQL ...
- 在线建立或重做mysql主从复制架构方法(传统模式和GTID模式)【转】
mysql主从复制架构,是mysql数据库主要特色之一,绝大多数公司都有用到. 而GTID模式是基于事务的复制模式的意思,发展到现在也是越来越多人用. 以前很多文章,介绍搭建mysql主从复制架构,是 ...
- Centos7.5部署MySQL5.7基于GTID主从复制+并行复制+半同步复制+读写分离(ProxySQL) 环境- 运维笔记 (完整版)
之前已经详细介绍了Mysql基于GTID主从复制的概念,原理和配置,下面整体记录下MySQL5.7基于GTID主从复制+并行复制+增强半同步复制+读写分离环境的实现过程,以便加深对mysql新特性GT ...
- MySQL-5.6版本GTID的主从复制
mysql GTID Replication 一.GTID的概述: 1.全局事物标识:global transaction identifieds. 2.GTID事物是全局唯一性的,且一个事务对应一个 ...
- MySQL主从复制之GTID模式介绍
GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. GTID概述 MySQL5.6 在原有主从复制的基础上增加了一个新的复制方式,即基于GTID的复制方式,它由UUID和事务 ...
- MySQL5.6基于GTID的主从复制配置
全局事务标示符(Global Transactions Identifier)是MySQL 5.6复制的一个新特性. GTID实际上是由UUID+TID组成的.其中UUID是一个MySQL实例的唯一标 ...
- Linux centosVMware Linux集群架构LVS DR模式搭建、keepalived + LVS
一.LVS DR模式搭建 三台机器 分发器,也叫调度器(简写为dir) davery :1.101 rs1 davery01:1.106 rs2 davery02:11.107 vip 133.200 ...
随机推荐
- 11G 新特性之 密码延迟认证
11G 新特性之 密码延迟认证 11G 新特性之 密码延迟认证 Table of Contents 1. 特性简述 2. 特性潜在引发问题 3. 关闭特性 1 特性简述 为了防止用户密码的暴力破解,从 ...
- python-静态方法和类方法及其使用场景
静态方法和类方法 静态方法 我们在类中定义的方法都是对象方法,也就是说这些方法都是发送给对象的消息.实际上,我们写在类中的方法并不需要都是对象方法,例如我们定义一个"三角形"类,通 ...
- php URL处理函数
parse_url() basename() pathinfo() dirname() 用法 parse_url() 是一计算机函数,功能是解析一个 URL 并返回一个关联数组,包含 ...
- 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_08.RequestMapping注解的作用
用于建立请求URL和处理请求方法之间的对应关系. 增加一个testResuqestMapping方法来测试 把注解放在类上 服务器重新部署 再次重新部署 这次就可以请求到数据 了 注解放在类上:用来表 ...
- RabbitMQ问题解决
1.访问http://localhost:15672/#/,输入用户名.密码登录报错500 解决方法:在快捷程序处找到RabbitMQ Service -stop停止服务,然后再点击RabbitMQ ...
- Android的消息机制之ThreadLocal的工作原理
ThreadLocal 可以把一个对象保存在指定的线程中,对象保存后,只能在指定线程中获取保存的数据,对于其他线程来说则无法获取到数据. 日常开发中 ThreadLocal 使用的地方比较少,但是系统 ...
- 【生成树趣题】CF723F st-Spanning Tree
题目传送门 题意: 给定一个n个点m条边的无向联通图,没有重边和自环.给定s和t,求一棵生成树,使得s,t的度数不超过ds,dt.若有解,输出“Yes”和方案(多组方案输出任意一组),若无解,输出“N ...
- IIS配置安卓下载.apk文件
前提:你的.apk文件所在路径正确,例如:www.grainnews.com.cn:8002/Attach/Images/201807/20180712091842127.apk 1.打开IIS 2. ...
- 交换机安全学习笔记 第九~十章 HSRP VRRP
HSRP (Hot Standby Router Protocol) 热备份路由器协议 思科私有 HSRP消息使用UDP 端口号 1985(IPv6时为2029) 使用多播地址 224.0.0.2( ...
- poj2478(欧拉函数)
题目链接:https://vjudge.net/problem/POJ-2478 题意:给定n,输出集合中元素的数量,集合中的元素为最简小于1的分数,分子分母均属于[1,n-1]. 思路:理清题意后就 ...