MySQL Master-slave replication

Source: Internet
Author: User

MySQL database itself provides the master-slave replication function can easily achieve multiple automatic data backup, to achieve the expansion of the database. Replication between MySQL is based on binary log files, a MySQL database once the binary log is enabled, its as master, other databases as slave through an I/O thread to maintain communication with the primary server, and monitor the master binary log file changes, If the master binary log file is found to change, it will copy the changes to its own trunk log, and then one of the slave SQL threads will execute the relevant "events" into their own database, in order to achieve consistency from the database and the primary database, and then implement the master-slave replication.

Building MySQL master-slave replication requires preparation in advance:

Primary server ip:192.168.177.128

From server 1ip:192.168.177.151

From server 2ip:192.168.177.152

Build MySQL master-slave synchronization:

Primary server:

? 1. Turn On time synchronization

 systemctl stop firewalld.service  //关闭防火墙 setenforce 0 yum -y install ntp //安装ntp vim /etc/ntp.conf   //添加如下2行     server 127.127.177.0                    //本地是时钟源//    fudge 127.127.177.0 stratum 8          //设置时间层级为8(限制在15内)// systemctl restart ntpd.service    //重启ntpd服务
 在这里我装的是mysql5.5,在之前我有安装过,可以看我以前的博客。
  

??? ? Vim/etc/my.cnf?? Enter configuration file

?????????? Server-id?????? = 11
?????????? Log-bin=master-bin???????????????????????? Primary server log File//
?????????? Log-slave-updates=true???????????????????? Update binary log from server//

??? Systemctl Restart Mysqld.service???? Restart Service
3. Go to MySQL

?? Mysql-u Root–p??? abc123

????

From server (two from server configuration identical):

? 1. Turn On time synchronization

?????? Yum install NTP ntpdate–y//Installation NTP

??? Systemctl start Ntpd.service//Open NTPD Service
?????systemctl stop firewalld.service //关闭防火墙

? setenforce 0

? /usr/sbin/ntpdate 192.168.177.128??? Time synchronization, enter the address of the primary server//

2. Install MySQL

  在这里我装的是mysql5.5,在之前我有安装过,可以看我以前的博客。
  

? Vim/etc/my.cnf

??? Server-id?????? = 22

??? Relay-log=relay-log-bin???????????????????????? Synchronize log files from the primary server logging to local//
??? Relay-log-index=slave-relay-bin.index?????????? Define the location and name of the Relay-log//
???????????

? Systemctl Restart Mysqld.service???? Restart Service

3. Go to MySQL

? Mysql-u Root–p??? abc123

?????

?????

There's another one from the server I'm not here to configure, and the other one is exactly the same as this one.

Verify Master-Slave synchronization:

In the main server (192.168.177.128): Create a new database

In the slave server (192.168.177.151): see if there is a newly created database

Above, verify master-Slave synchronization

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.