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的 ...
随机推荐
- 设计模式-Runoob:设计模式
ylbtech-设计模式-Runoob:设计模式 1.返回顶部 1. 设计模式 设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用.设计模式是软件开发 ...
- MM理论
最初的MM理论,即由美国的Modigliani和Miller(简称MM)教授于1958年6月份发表于<美国经济评论>的“资本结构.公司财务与资本”一文中所阐述的基本思想.该理论认为,在不考 ...
- C#怎么让字符串定长,不够的用空格补齐
string.PadLeft 或者 string.PadRight : string.PadLeft 表示如果一个字符串的长度小于指定的值,则在字符串的左侧(也就是前面)用指定的字符填充,直到字符串 ...
- ETROBOT——审题
参加了比赛,但是总要理解比赛相关的东西,发现以前瞎写的东西有人看,并且还有挺多人看的,所以打算继续在这里面,做记录. 源: http://www.etrobo.jp/2018/gaiyou/intro ...
- Mac013--Docker安装
一.Docker安装教程 参考:http://www.runoob.com/docker/macos-docker-install.html 可应用brew命令安装,也可自定义下载安装. 应用brew ...
- SQL语句创建函数
----先create,再alter alter function fuc (@userid int,@strWhere varchar(max),@strWhere2 varchar(max) ) ...
- vue组件通信之父子组件通信
准备工作: 首先,新建一个项目,如果这里有不会的同学,可以参考我转载过的文章 http://www.cnblogs.com/Sky-Ice/p/8875958.html vue 脚手架安装及新建项目 ...
- mysql数据库监控工具-MONyog的配置和基本使用项
测试数据传输前,研发要求需要监控10万,50万,100万数量级的数据在传输过程数据库服务器的资源消耗情况,因为数据传输服务是定时任务执行,配置10秒中一次,一次处理500条,处理完10万数据可能要半个 ...
- Consul集群Server模式
Consul集群Server模式 架构示意图 Consul在生产环境下运行模式分为两种:Server模式和Client模式(dev模式属于开发模式不在这里讨论),我们先用Server模式搭建一个Con ...
- C# DataTable 去重复数据方法
//获取dt中Id,Value 2个字段不重复的数据 newDt = dt.DefaultView.ToTable(true, "Id","Value" );