实现步骤如下:
1. 将主数据库设置为只读模式
show variables like '%read_only%'
set @@global.read_only=ON
创建一个复制用户
grant replication slave on *.* to repl@'%' identified by 'test2018' ;
2. 关闭Mysql服务
3. 将data目录下的db_pldb文件夹以及ibdata1文件压缩成 data压缩包
4. 修改主数据库的配置文件 my.ini
server-id=2
log-bin=mes-bin-2
binlog-do-db=db_test
binlog-ignore-db=mysql
binlog_cache_size=30M
binlog_format=mixed
binlog_row_image=minimal
max_binlog_size=300M
expire_logs_days=7
sync_binlog=1
gtid_mode=on
enforce-gtid-consistency=true
5. 启动Mysql服务
6. 在主数据上执行 reset master, 在此处主数据库的配置完成
7. 将data压缩包 传输到 从数据库的服务器上
8. 解压压缩包,将文件放置到data目录下
9. 启动从数据库服务
创建一个复制用户
grant replication slave on *.* to repl@'%' identified by 'test2018' ;
10. 新建db_test_backup数据库,并将db_test数据库中的数据全部拷贝到db_test_backup数据库中
11. 删除db_test库
12. 关闭从数据库服务
13. 配置从数据库
server-id=1002
log-bin=mes-bin-1002
binlog-do-db=db_test_backup
binlog-ignore-db=mysql
binlog_cache_size=30M
binlog_format=mixed
max_binlog_size=300M
expire_logs_days=7
log-slave-updates=ON
master-info-repository=TABLE
relay-log-info-repository=TABLE
max_relay_log_size=300M
relay_log=mes-relay-10023
#skip-slave-start=1
gtid-mode=ON
enforce-gtid-consistency=true
sync-binlog=1
replicate-rewrite-db="db_test->db_test_backup"
14. 启动从数据库服务
15.
reset master
reset slave
16.
change master to master_host='127.0.0.1',master_port=3306,
master_user='repl',master_password='test2018',master_auto_position=1;
17.
start slave
show slave status,
到此工厂从数据库配置完毕
从数据库到总部配置:
19. 总部配置
sync_binlog=1
gtid_mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
max_relay_log_size=300M
relay_log=mes-relay-20023
skip-slave-start=1
20. 将工厂从数据库设置为只读模式
show variables like '%read_only%'
set @@global.read_only=ON
创建一个复制用户
grant replication slave on *.* to mesrepl@'%' identified by 'Mes20180306' ;
set global read_only=1;
show global variables like "%read_only%";
-- 锁表
flush tables with read lock;
-- 解锁
unlock tables;
21.在总部数据库传输工厂从数据库数据(与从数据库名保持一致);
22.reset master;
23。
change master to master_host='127.0.0.1',master_port=3306,
master_user='repl',master_password='test2018',master_auto_position=1 for channel 'db_test_backup';
24.start slave;
25.show slave status;