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.