MySQL Master-slave replication
- MySQL master-slave replication is an asynchronous replication process in which the main library sends update events to the library, reads the update records from the library, and executes the update records, keeping the contents of the library consistent with the main library.
Experimental environment
Host |
IP Address |
main software |
Primary server |
192.168.27.128 |
Mysql5.7.17;ntp |
From server 1 |
192.168.27.139 |
Mysql5.7.17;ntp |
From server 2 |
192.168.27.142 |
Mysql5.7.17;ntp |
Build Master-slave replication 1, host Server setup time synchronization environment
Systemctl Stop Firewalld.service
Setenforce 0
Yum Install Ntp-y
Vim/etc/ntp.cnf
service 127.127.1.0 #本地时钟源fudge 127.127.1.0 stratum 8 #设置层级为8
Systemctl Start Ntp.service #开启服务
2, two time synchronization from the server
Systemctl Stop Firewalld.service
Setenforce 0
Yum Install Ntp-y
Systemctl Start Ntp.service
Yum Install Ntpdata-y
/usr/sbin/ntpdata 192.168.27.128 #进行时间同步
3, with the primary server
Vim/etc/my.cnf
server-id = 11log-bin=master-bin #主服务器二进制日志log-slave-updates=true #允许从服务器和主服务器同步
Systemctl Restart Mysqld.service
Mysql-u root-p #进入目mysql
Grant replication Slave on . to ' myslave ' @ ' 192.168.27.% ' identified by ' 123456 '; #允许192.168.27.0 network segment from the server using the account password login
Flush privileges; #更新权限
Show master status; #查看主服务器状态
4, configuration from the server (two from the server configuration is the same)
Vim/etc/my.cnf
server-id = 22relay-log=relay-log-bin #开启中继日志relay-log-index=slave-relay-bin.index #确定中继位置
Systemctl Restart Mysqld.service
Mysql-u root-p
Change Master to master_host= ' 192.168.27.128 ', master_user= ' myslave ', master_password= ' 123456 ', master_log_file= ' Master-bin.000001 ', master_log_pos=603; #配置同步
Start slave;
show slave status\g; #查看slave状态
5. Testing
MySQL Master-slave replication