master 主机:10.10.10.215
slave 主机:10.10.10.216
检查 mysql-uuid 是否相同,相同则会报错
vim /var/lib/mysql/auto.cnf
1.主机配置
1.配置 my.cnf.
vi /etc/my.cnf
[mysqld]下
添加内容
log-bin=mysql-bin
log-bin = master-bin
log-bin-index = master-bin.index
binlog_format = mixed
server-id = 1
2.创建同步账号
登入mysql
mysql>CREATE USER 'sync'@'%' IDENTIFIED BY 'sync';
mysql>grant replication slave on *.* to 'sync'@'10.10.10.216' identified by 'sync';
mysql>flush privileges;
mysql>exit
重启mysql
service mysqld restart
登入mysql查看信息
mysql> use mysql;
select user,host from user;
mysql> show master status;
2.备机配置
1.配置 my.cnf
vi /etc/my.cnf
[mysqld]下
添加内容
log-bin=mysql-bin
log-bin = mysql-bin
binlog_format = mixed
server-id = 2
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
2.登入mysql
mysql>
CHANGE MASTER TO
MASTER_HOST='10.10.10.215',
MASTER_USER='sync',
MASTER_PASSWORD='sync',
MASTER_LOG_FILE='master-bin.000003',
MASTER_LOG_POS=120;
启动slave
mysql>start slave;
检查状态
mysql>show slave status \G
显示为成功连接
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
3.检查
检查master主机
#master 主机
登入master主机mysql
mysql> show processlist\G
看到上面的Command: Binlog Dump说明配置成功!
2.检查slave
登入slave主机mysql
show slave status \G
看到上面的Slave_IO_Running: Yes Slave_SQL_Running: Yes<em id="__mceDel">说明配置成功!</em>