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的 ...
随机推荐
- p2619 [国家集训队2]Tree I [wqs二分学习]
分析 https://www.cnblogs.com/CreeperLKF/p/9045491.html 反正这个博客看起来很nb就对了 但是不知道他在说啥 实际上wqs二分就是原来的值dp[x]表示 ...
- C# winform 键盘全局事件
本文转载自:http://www.cnblogs.com/yukaizhao/archive/2010/12/14/winform_keyup.html 在winform程序中给form添加了keyu ...
- 004-unity3d MonoBehaviour脚本方法简介
一.MonoBehaviour 1.公共方法 CancelInvoke Cancels all Invoke calls on this MonoBehaviour. Invoke Invokes t ...
- VMware vSphere 虚拟化简介
目录 目录 vSphere 简介 vSphere 提供的工具 vCenter vCenter 的功能 vCenter 管理界面上提供的操作功能 HOST CLUSTER TEMPLATE Virtua ...
- Java 基础-IO、stream 流、文件操作
输入输出流的分类 在 java.io 包中,包含了输入输出操作所需的类. I/O 流可以安装不同的标准分类: 按照流的方向分类: 输入流:将信息从代码外部输入代码 输出流:将代码得到的数据输出到文件. ...
- 16/7/8_PHP-对象的高级特性
对这个理解不太懂或者说 没有一个明确的用法,不知道该怎么使用,说到底还是不懂有什么用.我还是先把只是点复制过来 对象比较,当同一个类的两个实例的所有属性都相等时,可以使用比较运算符==进行判断,当需要 ...
- C#模块初始化注入
这个功能可以实现很多很有用的功能,比如程序集加密,Hook安装等.英文转载备忘. 原地址:https://www.coengoedegebure.com/module-initializers-i ...
- maximize_window()最大化浏览器和刷新当前页面refresh()
from selenium import webdriverdriver = webdriver.Firefox()driver.get("https://www.baidu.com&quo ...
- python每日一练:0004题
第 0004 题: 任一个英文的纯文本文件,统计其中的单词出现的个数. import re count = 0 with open('./EnglishText.txt','r') as f: tem ...
- JAVA总结--正则表达式
正则表达式定义: pattern 对象是一个正则表达式的编译表示.Matcher 对象是对输入字符串进行解释和匹配操作的引擎.PatternSyntaxException 是一个非强制异常类,它表示一 ...