MySQL 5.6 X64 & CentOS 7 X64
Main Library: 192.168.1.1
From library: 192.168.1.2
1. Main Library Configuration
Vi/etc/my.conf
Set the following parameters under [mysqld]:
Server-id=1 #主库标识
Log_bin=mysql-bin #开启mysql二进制日志
#binlog-do-db=mydb #要复制的数据库
#binlog-ignore-db=mysql #忽略的数据库
Save exit, restart Service, view host binary log status
Service MySQL Restart
Mysql-u root-p
Show master status; #查看主服务器状态
+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 616 | Osyunweidb | MySQL |
+------------------+----------+--------------+------------------+
1 row in Set (0.00 sec)
To open an account from the server, user name sync limit IP, only give replication permissions
Grant Replication Slave on * * to ' sync ' @ ' 192.168.1.2 ' identified by ' 123456 ' with GRANT option;
Flush privileges;
2, from the library configuration
Vi/etc/my.conf
Set the following parameters under [mysqld]:
server-id=2 #从库标识位
Log-bin=mysql-bin
#binlog-do-db=mydb #要复制的数据库
#binlog-ignore-db=mysql #忽略的数据库
Save exit, restart Service
Service MySQL Restart
Mysql-u root-p
Slave stop; # Stop from library feature
Change Master to master_host= ' 192.168.1.1 ', master_user= ' sync ', master_password= ' 123456 ', master_log_file= ' Mysql-bin.000001 ', master_log_pos=616;
#设置同步参数 Host user name password binary file location
Slave start; # Start from library feature
Show slave status \g #查看从库状态
Slave_io_running:yes #是指读取主库二进制日志的进程状态
Slave_sql_running:yes #是指从库执行二进制日志的状态
Both of these are yes, which means that the binary operations logs from the library are read from the main library and executed synchronously in the native
MySQL Master-slave replication