Mysql Master/Slave configuration (image and text), mysql Master/Slave Configuration

Source: Internet
Author: User

Mysql Master/Slave configuration (image and text), mysql Master/Slave Configuration

I am not very busy recently. I will record the master-slave configuration process of the mysql database. If you have any shortcomings, please correct them.

# Environment configuration #
Master IP: 192.168.46.20.slave IP: 192.168.46.138 database: v1

1. Install the mysql database on both machines and add the remote connection permission respectively.

2. Configure the master database

# Edit the mysql configuration file and add the following content #
Vim etc/my. cnf
Server-id = 1
Binlog-do-db = v1
Relay-log =/var/lib/mysql-relay-bin
Relay-log-index =/var/lib/mysql/mysql-relay-bin.index.
Log-error =/var/lib/mysql. err
Master-info-file =/var/lib/mysql/mysql-master.info.
Relay-log-info-file =/var/lib/mysql/mysql-relay-log.info.
Log-bin =/var/lib/mysql-bin
After editing, restart mysql and systemctl restart mysqld. service (centos7 directly uses the systemctl command)
Create a replication user with the replication slave permission
Grant replication slave on *. * to 'user3' @ '192. 168.46.138 'identified by 'user3 ';
Username: user3 password: user3
Flush privileges;
# Viewing the status of the master database #
Show master status;

Remember the FileSet and Position values, which will be used in subsequent steps.

3. Configure slave Database

# Edit the slave database configuration file and add the following content #
Vim etc/my. cnf
Server-id = 2
Replicate-do-db = v1
Relay-log =/var/lib/mysql-relay-bin
Relay-log-index =/var/lib/mysql/mysql-relay-bin.index.
Log-error =/var/lib/mysql. err
Master-info-file =/var/lib/mysql/mysql-master.info.
Relay-log-info-file =/var/lib/mysql/mysql-relay-log.info.
Log-bin =/var/lib/mysql-bin
Note: The server-id in the two database configuration files cannot be the same
Restart mysql
Mysql-u root-pxxx
Change master to master_host = '192. 168.46.137 ', master_user = 'user3', master_password = 'user3', master_log_file = 'mysql-bin.000003', master_log_pos = 192;
# Start the slave thread #
Start slave;
# Check the slave status. Note that G is not followed by a semicolon #
Show slave status \ G

The red arrow indicates two parameters. If Yes, the configuration is successful. If Slave_IO_Running is connecting, check the firewall, whether the port is open, whether the FIle and Position parameters are consistent, and whether the network is smooth.
At this point, the mysql Master/Slave configuration is complete. You can add new data to check whether the data has been synchronized.

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.