系统环境:centos6.7 32 mysql
master ip:192.168.16.110
slave ip: 192.168.16.12
主服务器
1.vim /etc/my.cnf
追加以下内容:
[mysqld]
log-bin=test-log #启用二进制文件
server-id=110 #服务器编号
2.重启主服务的mysqld和关闭防火墙
server mysqld restart
server iptables stop
3.添加从服务器可以连接的用户
mysql -uroot -p
create user 'slave'@'192.168.16.12' identified by 'slave';
grant replication slave on *.* to 'slave'@'192.168.16.12';
exit
4.获取主服务器二进制日志信息
mysql -uroot -p
flush tables with read lock;
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 3550020 | | |
+------------------+----------+--------------+------------------+
unlock tables;
从配置:
vim /etc/my.cnf
追加以下内容:
[mysqld]
server-id=12 #服务器编号
2.重启主服务的mysqld和关闭防火墙
server mysqld restart
server iptables stop
3.连接主服务器配置
mysql -u root -p
change master to master_host='192.168.16.110',
master_user='slave',
master_password='slave',
master_log_file='mysql-bin.000009',
master_log_pos=3550020;
start slave;
show slave status\G
数据同步验证:
create database test2;
user test2
create table t_table(
name char(20),
age int,
note varchar(50));
insert into t_table values
('rocky','23','shanghai');
exit
转载于:https://blog.51cto.com/rockycai/1903517