MySQL 5.6 X64 & CentOS 7
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 #查看从库状态
Normal configuration, you can start synchronizing from the library by reading the binary log of the main library.
Slave_io_running:yes
Slave_sql_running:yes
Slave_io_running refers to the process state that reads the main library binary log slave_sql_running is the state of the binary log executed from the library
Both of these are yes, which means that the binary operations log from the library reads the main library and executes synchronously in the native, which naturally realizes the function of master-slave replication.
MySQL Master-slave configuration