MySQL Master-slave replication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.