MySQL master-slave replication deployment process

Source: Internet
Author: User
Tags egrep

Environment Preparation:

Deploy a master one from two servers, achieve master-slave replication, the main library to open Binlog, the main library and the Server-id from the library to be different

Main Library:

[Email protected] ~]# hostname-i

10.0.0.51 172.16.1.51

[Email protected] ~]# egrep "Log_bin|server-id"/etc/my.cnf

Server-id = 1 #主库的Server-id

Log_bin = Mysql-bin #开启binlog

From library:

[Email protected] ~]# hostname-i

10.0.0.52 172.16.1.52

[Email protected] ~]# egrep "Server-id"/etc/my.cnf

Server-id = 2 #从库的Server-id


Main Library Operations:

1, create the user, for the master-slave connection

mysql> grant replication Slave on * * to ' rep ' @ ' 172.16.1.% ' identified by ' 123456 ';

mysql> flush Privileges;

Mysql> select User,host from Mysql.user;


2, lock table, prohibit writing data

Mysql> Flush table with read lock;


3. Open a new window to export the main library data

[Email protected] ~]# Mysqldump-a-B--master-data=2 >/opt/3306.sql


4, unlock, open user Write function

mysql> unlock tables;


5. Copy the backup data from the main library to the library

[Email protected] ~]# Scp/opt/3306.sql 172.16.1.52:/opt/



From library operations:

1. Import the master library to the Slave library

[[email protected] ~]# MySQL </opt/3306.sql


2, find Binlog location point

[Email protected] ~]# sed-n ' 22p '/opt/3306.sql

--Change MASTER to master_log_file= ' oldboy-bin.000010 ', master_log_pos=405;


3, Configuration Master.info

Change MASTER to

Master_host= ' 172.16.1.51 ',

master_port=3306,

Master_user= ' rep ',

Master_password= ' oldboy123 ',

Master_log_file= ' mysql-bin.000010 ',

master_log_pos=405;


4. Turn on the sync function to view the status

mysql> start slave;

Mysql> Show Slave Status\g


The following status information appears indicating that the master-slave replication configuration was successful

Slave_io_running:yes

Slave_sql_running:yes

seconds_behind_master:0

This article from the "12206254" blog, reproduced please contact the author!

MySQL master-slave replication deployment process

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.