Linux to specify the MYSQL database server master-Slave synchronization configuration instance _mysql

Source: Internet
Author: User

First, the concept:
① Database Synchronization (master-slave Synchronous---Primary database writes to write data from server)
② database Synchronization (primary primary Sync---Two database servers write data to each other)

Second, for example
Database Server (A) Primary Database ip:192.168.1.134
Database Server (B) Primary Database ip:192.168.1.138
Two servers sync user name: bravedu Password: brave123

First, the main database operation settings (a):
① Create a sync user name allow connected User IP address (non-native IP)

Copy Code code as follows:

Grant replication slave on *.* to ' bravedu ' @ ' 192.168.1.% ' identified by ' brave123 ';
Flush privileges;

② Change MySQL configuration file
Copy Code code as follows:

[Mysqld]
Server-id = 1
Log-bin=/www/mysql/binlog/binlog (path to be set according to its own installation)
Binlog-do-db = dbname (the name of the database to be synchronized)
Binlog-ignore-db=mysql

Restart the MySQL server

③ View Primary Database sync status

Copy Code code as follows:

Mysql>flush tables with read lock;
Mysql>show Master Status\g
1. Row ***************************
FILE:MYSQL-BIN.000001 (note here to use when setting from the server)
position:106 (note here to use when setting from the server)
Binlog_do_db:dbname
Binlog_ignore_db:mysql
1 row in Set (0.00 sec)

Mysql>unlock tables;
The primary server is set up at the current location ***********

Two, from the database operation Setup (B):

① Create sync User name

Copy Code code as follows:

Grant replication slave on *.* to ' bravedu ' @ ' 192.168.1.% ' identified by ' brave123 ';
Flush privileges;

② Change MySQL configuration file
Copy Code code as follows:

[Mysqld]
Server-id = 2
Log-bin=/www/mysql/binlog/binlog (path to be set according to its own installation)
Binlog-do-db = dbname (the name of the database to be synchronized)
binlog-ignore-db= Mysql,information_schema

Restart the MySQL server

③ Specifies the master-slave database server synchronization instructions
Note: IP Primary server IP, username, password, log_file,log_post and the main server unified
This operation may need to unlock the table first, stop the database state, after running in the startup state

Copy Code code as follows:

mysql > Stop slave;
MySQL > Change master to master_host= ' 192.168.1.134 ', master_user= ' bravedu ', master_password= ' brave123 ', Master_log _file= ' mysql-bin.000001 ', master_log_pos=106;
mysql > Start slave;
mysql > Unlock tables;

④ View the primary database synchronization state will come out a lot of information but mainly look at these two states on the line if you are yes.
Copy Code code as follows:

Mysql>show slave status\g;
Slave_io_running:yes
Slave_sql_running:yes

At this point, the master-slave database synchronization configuration completed.

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.