First Step: Environment configuration
Clone and configure two hosts, one for master and one for slave. and shut down the firewall.
SYSTEMCLT Disable FIREWALLD
Step Two: Modify Master Host
Modify the master host's my.cnf
[Mysqld]
#port =3306
Character-set-server=utf8
Log-bin=/var/mysql/log/mysql-bin.log
Server-id=1 #唯一, the last IP address is recommended
Create a/var/mysql/log directory
Mkdir-p/var/mysql/log
Modify the owner of the/var/mysql directory
Chown-r Mysql:mysql./mysql
Restart Master's mysqld service
Systemctl Restart Mysqld
Step three: Modify the slave host
Modify the my.cnf of the slave host
[Mysqld]
#port =3306
Character-set-server=utf8
server-id=2 #ip Address Last
Modify the UUID of MySQL in the slave host
UUID, universal unique identification code
Cat/var/lib/mysql/auto.cnf
Mv/var/lib/mysql/auto.cnf/var/lib/mysql/auto.cnf.bak
Restart Slave's mysqld service
Systemctl Restart Mysqld
Fourth step: Master authorization Slave copy permissions
Master Licensing Slave Copy permissions
Log in to master MySQL
Mysql-uroot-proot
Authorized
Grant Replication Slave on * * to ' root ' @ ' 192.168.181.138 ' identified by ' root ';
Restart Master's mysqld service
Systemctl Restart Mysqld
Log in to Master's MySQL again
Mysql-uroot-proot
View Master Status
Show master status;
Fifth step: Slave Specify Master
Log in to slave MySQL
Mysql-uroot-proot
Specify Master
Change Master to master_host= ' 192.168.181.137 ', master_user= ' root ', master_password= ' 111 ', master_log_file= ' Mysql-bin.000002 ', master_log_pos=154;
Restart Slave's mysqld service
Systemctl Restart Mysqld
Log in to slave MySQL
mysql-uroot-p111
Open slave
Start slave;
View slave status
show slave status;
MySQL Master-slave replication