标签:
实现过程:
(1) master将改变记录到二进制日志(binary log)中(这些记录叫做二进制日志事件,binary log events);
(2) slave将master的binary log events拷贝到它的中继日志(relay log);
(3) slave重做中继日志中的事件,将改变反映它自己的数据。
相关命令:
mysql> start slave; #启动slave
mysql> stop slave; #停止
mysql> show slave status \G; #查看slave状态
mysql> reset slave; #重置slave配置
mysql> show master status; #查看bin-log状态
配置实现:
master配置(在my.cnf):
server-id=129
log-bin=mysql-bin
binlog-format=mixed
slave配置(在my.cnf):
server-id=130
relay-log=mysql-relay
在master上创建账号并授权:
mysql> grant replication client,replication slave on *.* to ‘repl‘@‘172.%.%.%‘ identified by ‘repl‘;
mysql> FLUSH PRIVILEGES;
在slave上设置:
mysql> change master to
-> master_host=‘172.16.24.129‘,
-> master_user=‘tianbao‘,
-> master_password=‘tianbao‘,
-> master_log_file=‘mysql-bin.000002‘,
-> master_log_pos=1099;
mysql> start slave;
遇到的问题:
#查看servid和配置文件中是否一致
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
#重置slave(reset slave),并且从新配置,然后启动slave
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
#状态不对。检查授权账号信息,检查日志文件的起始位置master_log_pos是否和master的一致。 show master status 查看bin-log信息
Slave_IO_State: Connecting to master .
标签:
原文地址:http://www.cnblogs.com/wtb123456/p/4542897.html