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的 ...
随机推荐
- Rtmp AAC基本格式(转)
第一个audio data包:AAC sequence header 第二个audio data包:AAC raw AF表示的含义: 1)第一个字节af,a就是10代表的意思是AAC, Format ...
- SQL Server创建链接服务器
1.通过sql语句创建链接服务器,数据是sql server的 EXEC sp_addlinkedserver @server='test', --链接服务器别名,自定义 @srvproduct='' ...
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_02 递归_1_递归概念&分类&注意事项
a方法里面调用自己,但是没有停止的条件 方法没有停止的条件. 栈内存溢出的异常. 只有栈,没有堆内存 先执行main方法压栈执行 main方法里面调用a方法.a方法就会压栈 改成20000
- NoSQL基础学习
NoSQL基础学习 最近学习的第一个Nosql就是Mongodb,为了了解Nosql的基本知识,特地总结,主要是学习Nosql的理论 一.Introduction(介绍) 它是“ Not Only S ...
- nested exception is java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator
原来的hibernate-validator-5.3.0.Final.jar里没有这个接口,换成 hibernate-validator-4.1.0.Final.jar 就好了
- CentOS7 iptables安装及操作
添加规则时的考量点: (1)要实现哪种功能:判断添加在哪张表上: (2)报文流经的路径:判断添加在哪个链上: 链上规则的次序: (1)同类规则(访问同一应用),匹配范围小的放上面: (2)不同类规则( ...
- enWin使用部分中文字库
在小型嵌入式设备中有时需要简单的人机2交互界面,小型GUI有很多,比较常用的有STenWin,UCGUI,enwin,Embedded Wizard GUI.对与STenWin和enWin区别主要在S ...
- 本地启oracle实例服务无法重启,协议适配器错误
今天遇到一位朋友的oracle实例服务无法起来,启动时报错: 分析的原因是可能早上服务器突然断电造成的,经过对tns的测试 经过我们讨论和诊断,最后诊断的处理方法是将实例删了重装,处理后服务恢复正常: ...
- Codeforces - 1198C - Matching vs Independent Set - 贪心
https://codeforces.com/contest/1198/problem/C 要选取一个大小大于等于n的匹配或者选取一个大小大于等于n的独立集. 考虑不断加入匹配集,最终加入了x条边. ...
- wxpython模板程序,包括各个实例
#coding=utf-8 import wx import time import os class MyApp(wx.App): def __init__(self): wx.App.__init ...