系統環境: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