linux下不重启建立正在运行数据库的从库

来源:互联网 发布:采购流程及优化 编辑:程序博客网 时间:2024/06/06 01:10
1、备份主库

mysqldump -uroot -p123456 --routines --single_transaction --master-data=2 --databases test > test.sql

2、从库导入备份库

mysql -uroot -p123456 -e 'create database test;' 

mysql -uroot -p123456 test < test.sql

mysql -uroot -p123456 -h127.0.0.1 -P6666 test < test.sql

3、在备份文件test.sql查看binlog名称以及pos位置值

 head -50 test.sql 

类似

-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=66666;  

4、设置主从关系  

   CHANGE MASTER TO
   MASTER_HOST = '127.0.0.1',
   MASTER_PORT = 6667,
   MASTER_USER = 'root',
   MASTER_PASSWORD = '123456',
   MASTER_LOG_FILE = 'mysql-bin.000066',

   MASTER_LOG_POS = 66666;

5、开启同步
   START SLAVE;