Linux学习-基于CentOS7的MySQL5.7的GTID复制
一、GTID复制简介
GTID (global transaction id)全局事务标识符,MySQL5.6版本开始支持,GTID复制不像传统的复制方式(导步复制、半同步复制)需要找到binlog和POS点,只需要知道master的IP、端口、账号、密码即可。
二、相关实验配置
实验用到两台主机,一台作为主服务器(192.168.214.17),一台作为从服务器(192.168.214.27),系统为CentOS7.6,数据库这mysql-5.7.26,使用二进制安装包进行安装。
1、二进制安装mysql
1). 准备安装包文件,可以在官网下载:https://dev.mysql.com/downloads/mysql/
[root@centos7 ~]# ll mysql-5.7.-el7-x86_64.tar.gz
-rw-r--r-- root root Dec : mysql-5.7.-el7-x86_64.tar.gz
2). 创建mysq用户
[root@centos7 ~]# useradd -r -s /sbin/nologin mysql
3). 准备二进制程序
[root@centos7 ~]# tar -zxvf mysql-5.7.-el7-x86_64.tar.gz -C /usr/local/
[root@centos7 ~]# cd /usr/local/
[root@centos7 local]# ln -s mysql-5.7.-el7-x86_64/ mysql #创建软链接
4). 初始化数据库
[root@centos7 mysql]# cd /usr/local/mysql
[root@centos7 mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql
--06T08::.399886Z [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
--06T08::.651036Z [Warning] InnoDB: New log files created, LSN=
--06T08::.680622Z [Warning] InnoDB: Creating foreign key constraint system tables.
--06T08::.758031Z [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7acd902a--11ea--000c290ae9d3.
--06T08::.759777Z [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
--06T08::.761255Z [Note] A temporary password is generated for root@localhost: _RluMerNq90# #记住此处数据库初始密码
5). 修改配置文件并配置环境变量
[root@centos7 mysql]# vim /etc/my.cnf
[root@centos7 mysql]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
[root@centos7 mysql]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos7 mysql]# . /etc/profile.d/mysql.sh
6). 准备服务启动脚本,并启动数据库服务
[root@centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@centos7 mysql]# chkconfig --add mysqld
[root@centos7 mysql]# chkconfig --list |grep mysqld Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld :off :off :on :on :on :on :off
[root@centos7 mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/mysql.log'.
SUCCESS!
7). 修改初始密码,连接测试
[root@centos7 mysql]# mysqladmin -uroot -p"_RluMerNq90#" password 'centos'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@centos7 mysql]# mysql -uroot -pcentos
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. MySQL Community Server (GPL) 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>
8). 从服务器也按以上步骤安装即可
2、GTID复制配置
1). 在主服务器(192.168.214.17)上修改配置文件 /etc/my.cnf
[root@centos7 mysql]# vim /etc/my.cnf
[mysqld]
server-id= #设置ID
log-bin #开始二进制日志
gtid-mode=on #开启gtid模式
enforce-gtid-consistency #开启gtid的一些安全限制
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid [client]
socket=/data/mysql/mysql.sock
2). 重启主服务器mysqld服务,登录数据库,创建拥有复制权限的用户账号
[root@centos7 mysql]# service mysqld restart
[root@centos7 mysql]# mysql -uroot -pcentos
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) 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> grant replication slave on *.* to repluser@'192.168.214.%' identified by 'centos';
Query OK, rows affected, warning (0.01 sec)
3). 在从服务器(192.168.214.27)上修改配置文件 /etc/my.cnf
[root@centos7- mysql]# vim /etc/my.cnf
[mysqld]
server-id= #设置ID
gtid-mode=on #开启gtid模式
enforce-gtid-consistency #开启gtid的一些安全限制
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid [client]
socket=/data/mysql/mysql.sock
4). 重启从服务器mysqld服务,登录数据库,配置用户用于连接主服务器,并启动复制线程
[root@centos7- mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@centos7- mysql]# mysql -uroot -pcentos
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. MySQL Community Server (GPL) 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> CHANGE MASTER TO
-> MASTER_HOST='192.168.214.17',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='centos',
-> MASTER_PORT=,
-> MASTER_AUTO_POSITION=;
Query OK, rows affected, warnings (0.05 sec) mysql> start slave;
Query OK, rows affected (0.00 sec)
5). 在主服务器上测试同步是否正常
[root@centos7 mysql]# mysql -uroot -pcentos
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.01 sec) mysql> create database db1; #主服务器建库
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) [root@centos7- mysql]# mysql -uroot -pcentos
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. MySQL Community Server (GPL) 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 | #可以看到从服务器已同步成功
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec)
Linux学习-基于CentOS7的MySQL5.7的GTID复制的更多相关文章
- Linux学习-基于CentOS7的LAMP环境实现多虚拟主机
一.实验环境 系统:CentOS7.6 主机:两台(一台也可以),一台实现apache+php-fpm (192.168.214.17),一台实现mysql服务器 (192.168.214.27) 软 ...
- Linux学习-基于CentOS7的ProxySQL实现读写分离
一.实验环境 主机:3台,一台ProxySQL(192.168.214.37),两台主从复制,master(192.168.214.17),slave(192.168.214.27) 系统:CentO ...
- Linux学习-基于CentOS7的MariaDB数据库的安装
一.实验环境: 系统:CentOS7.6,关闭了防火墙与SELINUX 数据库版本:mariadb-10.2.25(二进制安装与源码安装) 二.安装方法: 1.yum源安装 (1) 配置yum源,官方 ...
- Linux学习-基于CentOS7的MariaDB数据库的主从复制
一.MySQL主从复制原理 主从同步过程中主服务器有一个工作线程I/O dump thread,从服务器有两个工作线程I/O thread和SQL thread: 主服务器: dump Thread: ...
- MySQL5.7 的GTID复制
MySQL5.7 的GTID复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在MySQL5.6之后其官方推出了GTID复制方式,和传统的基于bin log复制方式有所不同,接 ...
- Linux环境基于CentOS7 搭建部署Docker容器
1.Docker容器概述 区分Docker容器技术和VM虚拟机技术: evernotecid://394EFE90-9CE0-4D65-A8CD-DFEC0DC8061E/appyinxiangcom ...
- 【Linux】 基于centos7.2 安装 LAMP
服务器选择的阿里云ecs服务器,系统centos7.2版 一.连接服务器,检查当前系统环境 1.查看centos版本 [root@iZuf682jnxmszwd2gdvzh0Z ~]# cat /et ...
- Linux学习(一)------CentOs安装mysql5.5 数据库
具体方法和步骤如下所示: 1.第一步就是看linu是否安装了mysql,经过rpm -qa|grep mysql查看到centos下安装了mysql5.1,那就开始卸载咯 2.接下来就是卸载mysql ...
- linux 学习 (基于ubuntu)
一. 在虚拟机中安装ubuntu 可参考如下博客: https://blog.csdn.net/u014337397/article/details/80751753 二. 关于linux的 ...
随机推荐
- wow64 32位进程中切换64位模式,取回64位寄存器值
32位dbg中编辑的: 7711E9D3 | 6A | | 7711E9D5 | E8 | 7711E9DA | | | 7711E9DE | CB | ret far | 6A E8 CB 64位d ...
- 1px渲染成2px的场景及解决方案
1.场景一: IE6 下默认div最小高度为2px,如何创建高为1px的容器? .minContainer{font-size:0px;overflow:hidden} 2.场景二: 移动端高分辨 ...
- 如何查看yum安装的程序包都放在哪些地方了?
yum安装, 是先下载下来, 然后安装, 用dnf代替yum后, 配置文件跟yum类似, 也是放在 /etc/dnf/ 目录下的, 也有dnf.conf 配置文件等 dnf list后面还可以跟参数: ...
- windows10下基于docker的bvlc/caffe环境搭建与使用
docker 安装参见docker官网,当cmd出现以下图像时安装正确; 然后进行bvlc/caffe环境创建,有两种,一种是直接pull github的bvlc,一种是本地创建image,直接使用g ...
- Django学习之模板
一.常用语法 1.变量 2.Filters 3.自定义filter 4.Tags 5.csrf_token 6.注释 7.注意事项 二.母板 2.继承母板 3.块(block) 4.组件 5.静态文件 ...
- Emmet - 自动补全 JSX
VSCode 中设置"emmet.syntaxProfiles": {"javascript": "jsx"} reactjs - JSX ...
- MVC4:ajax Json 应用
1)Json基础 2)Json 字符串和Json对象 3)应用例子 4)JsonHelper 1)Json 基础 JSON中对象通过"{}"来标识,一个"{}" ...
- Delphi XE2 之 FireMonkey 入门(11) - 控件居中、旋转、透明
RotationAngle.RotationCenter.Opacity 属性继承自 TControl(FMX.Types), 这些新属性成了控件的基本功能. 先在 HD 窗体上添加 TRectang ...
- 《Selenium 2自动化测试实战 基于Python语言》中发送最新邮件无内容问题的解决方法
虫师的<Selenium 2自动化测试实战 基于Python语言>是我自动化测试的启蒙书 也是我推荐的自动化测试入门必备书,但是书中有一处明显的错误,会误导很多读者,这处错误就是第8章自动 ...
- 东软、天健、金仕达、杭创、中联、NECHIS、军字一号 HIS产品的比较
HIS主流厂商产品介绍1.沈阳东软医疗系统有限公司创立于1998年公司是中国目前最大的软件集团——东软集团为技术和资源依托,以研制生产大型医疗设备为主,同时为医院数字化提供全面解决方案.但是,公司改制 ...