1、在master上修改/etc/my.cnf 添加:
log-bin=MySQL-bin
binlog-do-db=test
binlog-ignore-db=mysql
注:上面三条让之前的slave机也做成可同步的主机
重启mysql服务:service mysqld restart
2、授权给192.168.0.57
[root@desktop95 admin]# mysql -uroot -pwestos
mysql> grant replication slave,reload,super on *.* to 'slave'@'192.168.0.57' identified by '10000';
mysql> flush privileges;
在192.168。0.57上测试看能不能登录95的数据库:
[root@desktop57 ~]# mysql -uslave -p10000 -h 192.168.0.95
OK,成功登录。
3、在192.168.0.57(master)上修改/etc/my.cnf ,增加:
master-host=192.168.0.95 //设置从原 slave 数据库同步更新
master-user=slave //更新用户
master-password=10000 //密码
master-port=3306 //端口
replicate-do-db=test //需要更新的库
replicate-ignore-db=mysql //屏蔽对mysql库的同步
重启mysql服务:service mysqld restart
4、在192.168.0.95(原slave)查看状态:
[root@desktop95 admin]# mysql -uroot -pwestos
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 106 | test | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
记录下File(mysql-bin.000001),Position(106)
5、在192.168.0.57(原master)查看状态及加入工作群:
mysql> slave stop;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to master_host='192.168.0.95',master_user='slave',master_password='10000',master_log_file='mysql-bin.000001',master_log_pos=106;
Query OK, 0 rows affected (0.12 sec)
mysql> slave start;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.95
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 106
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes (I/O读写正常)
Slave_SQL_Running: Yes (mysql监听正常)
Replicate_Do_DB: test
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 106
Relay_Log_Space: 407
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
OK,都是两yes了,表明数据正常同步
