Mysql database master-slave Synchronization Process (1)

Source: Internet
Author: User
After reading the master-slave replication of mysql written in the old boy's blog oldboy. blog.51cto. com2561421339399, I recorded the test process as follows, including scripts, troubleshooting, and illustration.

I have read the old boy's blog

After reading the master-slave replication of mysql written in the old boy's blog, I recorded the test process as follows, including scripts, troubleshooting, and illustrated procedures. Due to the long length, it may be deleted. Please forgive me for reading this article. thanks to the old boy's video, although he is not a student, he also quietly thanked him for the video. The video's environment is in a multi-host, multi-instance environment, in addition, mysql may have been optimized, and my environment is on two machines. Please note that there is anything wrong with it.

1. Copy Preparation

Port is 3306

Port is 3306

Prepare the database environment, with two servers and one database for each machine.

2. perform operations on the master database

[Mysqld]

Server-id = 1

Log-bin = mysql-bi

Tip:

Restart.

/Etc/init. d/mysql restart

Mysql-uroot-p '000000'-S/tmp/mysql. sock

Mysql> select user (); view user

Table );

User access;

# Identified by "123456", 123456 is the password, Hong Kong space, it is better to be complex in the actual environment.

Check the created rep account again

Select user. host from mysql. user;

You can also view the user permission mysql> show grants for rep @ '2017. 192.% ';

2.3 read-only database lock tables (do not close the current window)

In the production environment, the master-slave replication operation on the Hong Kong server requires an application for downtime, and the lock table will affect the business.

Mysql> flush tables with read lock;

Prompt: The time of the lock table command is controlled by the following parameters in different engines. If the lock table exceeds the set time, it will be automatically unlocked;

Interactive_timeout = 60

Wait_timeout = 60

Default length:

Mysql> show variables like "% timeout %"; the default value is large.

2.4 view the status of the master database

View the status of the master database, that is, the current log file name and binary log offset.

Show master status; the information displayed by the command should be recorded, and the slave Database Replication follows should start from this position.

2.5 Export Database Data

Mkdir/server/backup/-p

Mysqldump-uroot-p "123123"-S/tmp/mysql. sock-A-B | gzip>/server/backup/mysql_bak. $ (date cannot exceed f2.16. SQL .gz

And other parameters (the database will directly overwrite all ).

Ls-l/server/backup/mysql_bak. $ (date must have f2.16. SQL .gz

To ensure that no data is inserted into the database during the Database Import process, you can check the status information of the master database.

Mysql-uroot-p "123123"-S/tmp/mysql. sock-e "show master status"

Note: The binlog file and its location remain unchanged unless otherwise specified.

After importing the database, unlock the master database and restore the database to write;

Mysql> unlock tables;

Note: Some readers may be confused about how much data is actually updated from the master database, the slave database will soon catch up with the master database position progress from the show master status position above.

Ls-l/server/backup/mysql_bak. $ (date must have f2.16. SQL .gz

Continue to pay attention to the master-slave synchronization process of the mysql database (II)

This article is from the "Wang Haipeng" blog. For more information, contact the author!

, Website Space

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.