Master端配置:
1.首先需要开启mysql数据库的二进制日志,需要制定mysql数据库的server-id
1 vim /etc/my.cnf(在配置文件中添加) 2 server-id=1 3 log-bin=binlog
2.修改root账户密码
1 update mysql.user set password=password("admin")where user="root" 2 flush privileges;(刷新配置)
3.添加slave线程账号
1 grant replication slave on *.* to "mysqlAB"@"%" identified by "mysqlAB";
Slave端配置:
1.首先需要开启mysql数据库的二进制日志,需要制定mysql数据库的server-id
1 vim /etc/my.cnf(在配置文件中添加) 2 server-id=2 3 log-bin=binlog
2.进入数据库手动指定Master服务器同步数据
1 mysql -u root -padmin 2 slave stop; 3 change master to 4 master_host="192.168.1.1", 5 master_user="mysqlAB", 6 master_password="mysqlAB", 7 master_log_file="binlog-000001";
8 slave start;
3.查看slave状态
show slave status; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.199 Master_User: mysqlAB Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000002 Read_Master_Log_Pos: 794 Relay_Log_File: mysqld-relay-bin.000015 Relay_Log_Pos: 248 Relay_Master_Log_File: binlog.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes
可以看到你手动指定的master的信息,IO和SQL线程为YES,ok配置完成,可以去mysql添加一个库来测试实验成功与否。