主服务器IP:192.168.1.11
从服务器IP:192.168.1.12
192.168.1.11主操作:
1、关闭防火墙、selinux
service iptables stop
setenforce 0
2、vim /etc/my.cnf
在[mysqld]下添加:
server_id = 1
log-bin=mysql-bin
binlog_format=mixed
log-slave-updates=true
3、连接到数据库,创建一个有复制权限的slave用户test进行远程连接slave
grant replication slave on *.* to‘test’@’192.168.1.%’ identified by ‘123’;
4、刷新授权
flush privileges;
5、重启mysql服务
service mysqld restart
6、查看master的状态信息
mysql> showmaster status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB |Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00sec)
192.168.1.12从操作:
1、关闭防火墙、selinux
serviceiptables stop
setenforce 0
2、vim /etc/my.cnf
在[mysqld]下添加:
server-id = 2
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
3、删除/usr/local/mysql/data/auto.cnf的uuid
[auto]
server-uuid=fe4179ff-ca1c-11e7-be22-000c29766e1e
4、重启mysql服务
service mysqld restart
[root@rooo ~]#service mysqld restart
shutting downMySQL. [ OK ]
startingMySQL. [ OK ]
5、配置slave连接master
change mastertomaster_host='192.168.1.11',master_user='test',master_password='123..com',master_log_file='mysql-bin-000001',master_log_pos=log_pos=120;
6、开启slave
resetslave
startslave
7、查看slave状态
show slave status;
slave_IO_Running: Yes
slave_SQL_Running: Yes