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.