Home  >  Article  >  Database  >  master/slave主从数据库手动同步之master-data_MySQL

master/slave主从数据库手动同步之master-data_MySQL

WBOY
WBOYOriginal
2016-06-01 13:31:40985browse

bitsCN.com

master/slave主从数据库手动同步之master-data

 

 master-data参数在建立slave数据库的时候会经常用到,因为这是一个比较好用的参数,默认值为1,默认情况下,会包含change master to,这个语句包含file和position的记录始位置。master-data=2的时候,在mysqldump出来的文件包含CHANGE MASTER TO这个语句,处于被注释状态

 

dump出文件

[root@aeolus1 c_learn]# mysqldump -uroot test --single-transaction --master-data=2 >master-data.sql过滤出change master to信息[root@aeolus1 c_learn]# grep -i "change master to" master-data.sql -- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000012', MASTER_LOG_POS=107;

 

 

然后修改 

change master to  master_host='xx.xx.xx.xx',master_user='repl',master_password='repl',master_port=3306,master_log_file='mysql-bin.000012',master_log_pos=107;

 

 

然后slave从库执行

 

mysql> change master to  master_host='xx.xx.xx.xx',master_user='repl',master_password='repl',master_port=3306,master_log_file='mysql-bin.000012',master_log_pos=107;

 

 

然后 

mysql>start slave 

 

 

再次执行 

mysql>show slave status;

 

 

需要注意的是:如果之前配置过服务器链接和密码,从服务器不用reset slave,直接

CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000012', MASTER_LOG_POS=107;
 即可。

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn