日期:2014-05-16  浏览次数:20928 次

mysql主从同步时遇到的问题




登录master机和slave机的mysql:mysql –u root –p ,一个有密码一个没有密码

两个都创建数据库:create database repl;

master :192.168.10.254
slave:192.168.10.204

1、设置master
编辑配置文件 /etc/my.cnf
server-id=1
binlog-do-db=repl

创建一个mysql的账号为同步专用
mysql –u root –p
mysql> grant replication slave on *.* to 'gl'@'192.168.10.204' identified by '123456';
mysql> flush privileges;

重启master mysql

mysql>show master status;
mysql-bin.000002  98 repl

mysql> show processlist;
2 gl 192.168.10.204:35315 has sent all binlog to slave;waiting for binlog to be updated
3 root localhost repl query showprocess

3、设置slave
编辑配置文件
server-id=2
master-user=gl                
master-host=192.168.10.254    
master-password=123456        
master-connect-retry=60      
master-port=3306              
replicate-do-db=repl          

然后重启slave mysql

在slave机中进入mysql
mysql>start slave;
mysql>show slave status\G;
Slave_IO_Running、Slave_SQL_Running状态为Yes

mysql>show master status;
waiting for master to send event 192.168.10.237 gl 3306 60 mysql-bin.000002 98 mysql-relay-bin.0000 repl


mysql> show processlist;
1 system user 3421 waiting for master to send event
2 system user 397 has read all relay log;waiting for the slave I/O thread to update it
5 root localhost query show processlist


后来我在主机的数据库里创建了一张表,但是从机上并没有显示,请问为什么,如何解决?


解决:
遇到问题后,又在主机重新创建了一个表,到从机上检查后发现表存在。
可能是由于表是在服务没有配置好之前建立的,没有同步上的原因