mysl 基于 GTID主从复制

注意:如果主mysql已经跑了一段时间,需要用备份软件把数据备份恢复到从服务器上去,确保主从服务器数据一致,否则可能报错,而且mysql 只有5.6 以后才支持gtid,安装时确保你的软件支持gpid
1.安装mysql
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm #下载mysql的yum源
yum install mysql57-community-release-el7-10.noarch.rpm -y # 安装yum源
yum -y install mysql-community-server -y #yum 安装mysql
2.编辑主配置文件

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
user=mysql
port=3306
server-id=1
gtid-mode=ON
enforce-gtid-consistency=ON
binlog_format=row
log-bin=log-bin
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
我都是用的rpm默认路径,实际安装自己需求该路径

3.编辑从文件

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
user=mysql
port=3306
server-id=2
gtid-mode=ON
enforce-gtid-consistency=ON
binlog_format=ROW
log-bin=log-bin
log_slave_updates=ON
skip-slave-start=1
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

4.创建具有复制权限的账号,在主的上面创建
grant replication slave on *.* to ‘rep‘@‘192.168.%.%‘ identified by ‘123456‘;
5.从服务器配置连接
进入mysql配置
change master to master_host=‘192.168.1.32‘, master_user=‘rep‘,master_password=‘123456‘,master_port=3306,master_auto_position=1;
6.启动同步,查看
start slave;#启动
show slave status;
mysl 基于 GTID主从复制这里两个yes 说明同步成功了

相关文章
相关标签/搜索