创新互联公司主要从事
网站建设、成都网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务叶集,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220MySQL 5.7 基于GTID搭建主从复制
一、搭建过程
1.1 准备三个MySQL实例
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3307/data/
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3308/data/
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3309/data/
1.2 server_id, server_uuid 不同
mysql -uroot -p123 -e "select @@server_id"
mysql -uroot -p123 -e "select @@server_uuid"
1.3 gtid_mode 是否开启:
mysql -uroot -p123 -e "select @@gtid_mode"
mysql -uroot -p123 -e "select @@server_gtid"
vi 330{7..9}/my.cnf
gtid_mode=ON
enforce_gtid_consistency=ON
log_slave_updates=ON
1.4 确认binlog开启
mysql -uroot -p123 -e "select @@log_bin"
1.5 备份主库数据到从库通过远程方式
mysqldump -uroot -p123 -h 192.168.84.30 -P 3307 > /tmp/full.sql
1.6 恢复数据
mysql> source /tmp/full.sql
1.7 主库创建复制用户
grant replication slave on *.* to repl@'192.168.84.30' identified by '123';
1.8 从库启动复制
帮助:
mysql> help change master to
......
找到配置模板:
CHANGE MASTER TO
MASTER_HOST='master2.example.com',
MASTER_USER='replication',
MASTER_PASSWORD='password',
MASTER_PORT=3306,
MASTER_LOG_FILE='master2-bin.001',
MASTER_LOG_POS=4,
MASTER_CONNECT_RETRY=10;
3308,3309使用如下配置:
CHANGE MASTER TO
MASTER_HOST='192.168.84.30',
MASTER_USER='repl',
MASTER_PASSWORD='123',
MASTER_PORT=3307,
master_auto_position=1;
开始配置3308
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.84.30',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='123',
-> MASTER_PORT=3307,
-> master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
开始配置3309
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.84.30',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='123',
-> MASTER_PORT=3307,
-> master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
分享题目:MySQL5.7基于GTID搭建主从复制-创新互联
分享网址:
http://cdxtjz.cn/article/popee.html