mysql主从--使用mysqldump 创建基于GTID的从库

–主库创建复制账号
GRANT REPLICATION SLAVE ON . TO ‘repl’@‘192.168.200.%’ IDENTIFIED BY ‘repl’;

–主库使用mysqldump备份并拷贝到备库
mysqldump -uroot -p -A -q --single-transaction -S /opt/mysql/data/mysql.sock --master-data=2 > /tmp/all.sql
[mysql@mysql8 ~]$ scp /tmp/all.sql 192.168.200.9:/tmp/
[email protected]’s password:
all.sql

–备库登陆mysql并source
[root@localhost][db01][02:11:50]> source /tmp/all.sql

–备库创建slave并启动
CHANGE MASTER TO MASTER_HOST=‘192.168.200.8’,
MASTER_USER=‘repl’,
MASTER_PASSWORD=‘repl’,
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;

start slave;
show slave status\G

注意事项:
1、由于备库是从主库克隆的一个环境,索引需要修改备库的server-id以及server_uuid
(1)修改server-id
[root@mysql8-2 ~]# cat /etc/my.cnf | grep server-id
server-id = 11

(2)修改server_uuid
[root@localhost][(none)][01:43:50]> show variables like ‘%server_uuid%’;
±--------------±-------------------------------------+
| Variable_name | Value |
±--------------±-------------------------------------+
| server_uuid | 240ef714-28e3-11e8-8155-000c292e1b80 |
±--------------±-------------------------------------+

[root@mysql8-2 ~]# cd /opt/mysql/data/
[root@mysql8-2 data]# vim auto.cnf
[root@mysql8-2 data]# cat auto.cnf
[auto]
server-uuid=240ef714-28e3-11e8-8155-000c292e1b81

重新启动slave上mysql服务器
slave节点:
[root@localhost][(none)][01:44:42]> show variables like ‘%server_uuid%’;
±--------------±-------------------------------------+
| Variable_name | Value |
±--------------±-------------------------------------+
| server_uuid | 240ef714-28e3-11e8-8155-000c292e1b81 |
±--------------±-------------------------------------+

如果不修改server_uuid 启动slave会有如下报错:
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

你可能感兴趣的:(MySQL)