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 ...
随机推荐
- csp2019 Emiya家今天的饭题解
qwq 由于窝太菜了,实在是不会,所以在题解的帮助下过掉了这道题. 写此博客来整理一下思路 正文 传送 简化一下题意:现在有\(n\)行\(m\)列数,选\(k\)个数的合法方案需满足: 1.一行最多 ...
- 《Java编程思想》读书笔记<一>
第二章 一切皆对象 java是面向对象的语言. 1.我们怎么操作对象? 每种语言都有自己的操纵内存中元素的方式,java使用引用操作内存中元素(对象).引用可以独立存在,例如:String s:表示创 ...
- MVC1:.Net MVC Cotroller向View传值
下面介绍 ASP .Net MVC中 Cotroller 向 View 传值 的4中方式: ViewBag,ViewData,TempData,Model. (注:参数可根据需要为复杂类型,只需在应用 ...
- django 数据库操作详解
Django配置使用mysql数据库 修改 settings.py 中的 DATABASES 注意:django框架不会自动帮我们生成mysql数据库,所以我们需要自己去创建. DATABASES ...
- Spring Boot 自定义注册 Servlet、Filter、Listener
前言 在 Spring Boot 中已经移除了 web.xml 文件,如果需要注册添加 Servlet.Filter.Listener 为 Spring Bean,在 Spring Boot 中有两种 ...
- 关于使用unittest单元测试框架的一些问题集
1.使用unittest.TestSuites生成的测试套件,使用HtmlTestRunner运行时报Type Error. 1)是由于使用unittest.TestSuites生成的测试套件里的Te ...
- Libra的思考
这几年关注了很多的新技术,近期让我觉得值得一讲的是blockchain,刚巧6.18号就发布了Libra 他是这么介绍自己的 libra https://developers.libra.org/bl ...
- No repository found containing: …错误解决
由于我安装的是Eclipse ForJava Development,无JAVA EE,查找资料后发现可以自己在已有软件的基础上配置,总结如下: >>>>>点开之后,找到 ...
- Mysql-慢查询排查
1.开启慢日志 2.使用show full processlist抓出慢查询语句 3.使用explain分析语句 4. set global profiling = ON
- 第七周课程总结&实验报考(五)
第七周课程总结&实验报考(五) 实验四 类的继承 实验目的: 1.理解抽象类与接口的使用: 2.了解包的作用,掌握包的设计方法. 实验要求: 1.掌握使用抽象类的方法. 2.掌握使用系统接口的 ...