Home  >  Article  >  Backend Development  >  Optimizing Availability with MySQL Built-in Replication (2)_PHP Tutorial

Optimizing Availability with MySQL Built-in Replication (2)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:21:52885browse

Step 1: Configure the main server
For the remainder of this article, I will specify two servers. A (IP is 10.1.1.1) serves as the main server (referred to as host). B (IP is 10.1.1.2) serves as the backup server (referred to as the backup server).
The implementation process of MySQL's replication function is as follows: the standby machine (B) connects to the host machine (A), then reads the binary update log of the host machine, and then merges the changes into its own database. The standby machine needs a user account to connect to the host, so create an account on the host and give it only FILE permissions, as follows:
GRANT FILE ON *.* TO replicate@10.1.1.2 IDENTIFIED BY "password";
In order for the standby machine to connect to the main machine, "FLUSH PRIVILEGES" needs to be run on the main machine, but don't worry, because we will stop the server in the following steps.
Now we need a snapshot of the host database and configure the host to allow binary update logs to be generated. First edit the "my.cnf" file to allow binary update logging, so somewhere below the [mysqld] section add a line: "log-bin". The next time the server starts, the host will generate a binary update log (named: $#@60;hostname$#@62;-bin.$#@60;increment number#$#@62;). In order to make the binary update log valid, shut down the MySQL service program, then move all database directories on the host to another directory, and then restart mysqld. Please make sure that all databases are obtained, otherwise when copying, if a table exists on the main machine but does not exist on the standby machine, it will exit due to an error. Now you have a snapshot of your data, and a binary log of any changes to the database since the snapshot was taken. Please note that MySQL data files (*.MYD, *.MYI and *.frm) are file system dependent, so you cannot just do a file transfer, such as from Solaris to Linux. If you are in a heterogeneous server environment, you will have to use the mysqldump utility or other custom scripts to get a snapshot of the data.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532379.htmlTechArticleStep 1: Configure the main server For the remainder of this article, I will specify two servers. A (IP is 10.1.1.1) serves as the main server (referred to as host). B (IP is 10.1.1.2) does...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn