MySQL5.7主从复制搭建-gtid方式
环境准备
1、主机名和和IP地址如下
10.0.0.51 db01.ljbb.com
10.0.0.52 db02.ljbb.com
10.0.0.53 db03.ljbb.com
2、配置文件
- db01
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=51
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
#log-slave-uodates=1
log_slave_updates = ON
[mysql]
prompt=db01 [\\d]>
- db02
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=52
port=3306
secure-file-priv=/tmp
autocommit=0
log-bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log_slave_updates = ON
[mysql]
prompt=db02 [\\d]>
- db03
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=53
port=3306
secure-file-priv=/tmp
autocommit=0
log-bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log_slave_updates = ON
[mysql]
prompt=db03 [\\d]>
3、准备软件用户
3台执行:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
4、准备软件目录(根据配置文件-保证权限)
mkdir /data/binlog/ -p
mkdir /data/mysql/data -p
chown mysql:mysql /data
chown mysql:mysql /app/mysql
5、初始化(3台执行)
mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql/data