17.1 MySQL Master-slave introduction 17.2 Preparation 17.3 Configure Master 17.4 configuration from 17.5 to test master-Slave synchronization

Source: Internet
Author: User

17.1 MySQL Master-slave introduction

Master is the Lord, Slave is from.

Main application scenarios: Backup, Backup + "from" machine can also read, (reduce the pressure of the main)

17.2 preparatory work

Two machines are required to install the MySQL service, and then start the MySQL service,

17.3 Configuring the Master

1. First modify the Lord's configuration file my.cnf, add the following two lines, Server-id after the parameters set themselves, Log_bin followed by the generation of Binlog prefix.

Restart MySQL After you've finished changing

Then/data/mysql will generate some files, the prefix is the character after the Log_bin to prevail.

2. Prepare a data for demonstration purposes, for example, we can make a backup of the blog,

Then create a new library,

Then we put the blog.sql data back in.

And then we can take a look, like line fourth, the aming database we just created.

(Aminglinux1.000001 records all the aming database, so you can restore the Aming database through this file)

3. Then we have to create a user, the user is the master-slave synchronization with each other, first into the MySQL inside,

Then create the user (Specify the permissions for replication slave, and then all the libraries for all the tables *. *, specify the ERPL user, then target the IP from, and then the password)

Then lock the table so that it doesn't write because we want to sync the data from it later. The two of them want to be consistent.

Then you have to do one and then remember the following two parameters.

Then quit MySQL, then we do a data synchronization, we first see which libraries need to be synchronized, we synchronize the following several libraries. Where MySQL is not synchronized.

where aming and blog have been backed up, is

Then we'll make a backup of MYSQL2 and Zrlog separately.

Then we'll copy all the SQL files from TMP to the back.

17.4 Configuration from

Check that the MySQL service has no boot, then look inside there are no server parameters, no need to add, here No, let's Add.

The Log_bin parameter is not configured, because only the master needs a binary file.

And then reboot, then we'll copy the number of our Lord's SQL to it and do a recovery of the data, here we use the SCP copy.

The command was not found because we did not create the path, we will give the following two alias

Then we log in to MySQL and create 4 libraries

Then exit and then restore the 4 databases separately.

And then we'll see if the/data/mysql directory is the same as the main machine.

Then we can begin to implement the master and slave.

Log on from MySQL and then it is a very critical step to implement master-slave

Specify the primary IP, specify the user, specify the password, specify the log file (the first of the two parameters we just remembered), specify the second value to remember,

Then we determine whether the master and slave have been successfully configured,

Take a look at the following position is not two yes,

If one is no, it means that your master and slave are disconnected.

Then we go back to the Lord and log in to MySQL to restore this table to write operations.

17.5 testing master-Slave synchronization

As above parameters are not mentioned in some of the parameters, their usage is added in the configuration file,

The first one is you just specify to synchronize the library, you add him in the main configuration file, later specify the library to be synchronized, if more than a comma separated.

The second one is to ignore one of the libraries and synchronize the others.

From the 12th ibid above, then the 34th one is to specify the synchronization table and omit the specified table (three or four caution, which in some cases results in incomplete data)

To insure we use 562 parameters (because it supports "libraries. Table "), such as all tables for aming this library, or all of them are ignored.

And then we'll test the master-slave

We do an operation in the Lord, we come to the Aming library, and then look at its table

Then we do an operation on its table, to see how many rows the users table is doing from the top, it should all be a row.

Then we'll clear the table and see how many rows it has, and then look at it from the top, and it should be 0.

And then we'll delete the watch and look at it from the top.

If we remove the modification from the top, it will cause the master to never agree, and then cause the disconnection.

Want to repair on the use of the following code, and then to see if there is no up, if not can only re-master from the.

Re-take the decision from: (First guarantee data always)

And then run it from the top

Lord, take a look at these two parameters,

Then run from the top

Then check that the master-slave connection status should be connected.

17.1 MySQL Master-slave introduction 17.2 Preparation 17.3 Configure Master 17.4 configuration from 17.5 to test master-Slave synchronization

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.