Use the MySQL built-in replication function

Source: Internet
Author: User

The internal replication function of MySQL is implemented between two or more servers by setting the master-slave relationship between them. One of them serves as the master server and the other as the slave server. This section describes how to configure two servers, one as the master server and the other as the slave server. And describes the process of switching between them. This section describes how to configure MySQL 3.23.25 and how to test it. It is recommended that MySQL developers use the latest version and the master-slave servers use the same version. At the same time, MySQL 3.23 is still a beta version, and this version may not be backward compatible.

  Configure the master server

We will specify two servers. A (IP address 192.168.0.1) serves as the master server (host for short ). B (IP address 192.168.0.2) is used as the slave server ).

  1. Create an account for backup

The replication function of MySQL is implemented by connecting slave machine (B) to host (A), and then reading the binary Update log of the host, then merge the changes into your own database. The slave needs a user account to connect to the host. Therefore, create an account on the host and grant only the FILE Permission to the account. The following operations are performed:

Mysql> grant file on *. * TO replicate@192.168.0.2 identified by password;

To connect the slave to the host, run flush privileges on the host:

Mysql> flush privileges;

But don't worry, because we will stop the server in the following steps.

  2. Modify the option File

Now we need a snapshot of the host database and configure the host to generate binary update logs. First, edit the my. cnf file to allow binary updates. Therefore, add a line below [mysqld]: log-bin. When the next server is started, the host generates a binary Update log named <Host Name>-bin. <incremental sequence number #> ).

[Mysqld]

Log-bin

To make the binary Update log valid, close the MySQL service program, then store all the database directories on the host to another directory, and restart mysqld.

Related Article

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.