Environment:
MySQL version is all 5.7 (previous version configuration may not be the same)
Master (Master) windows:192.168.0.68
From (Slave) centos7:192.168.0.4
Basic Environment configuration:
To ensure that firewall 3306 port is open, if only for learning, you can directly shut down the firewall.
CentOS Shutdown Firewall Method: Service iptables stop or systemctl stop FIREWALLD
Configuration of Master
Modify/ETC/MY.CNF
[Mysqld] log-bin=mysql-binserver-id=2binlog-ignore-db=information_schemabinlog -ignore-db=clusterbinlog-ignore-db=mysqlbinlog-do-db=test
Here the Server-id is used to identify a unique database, which must be set to a different value from the library.
BINLOG-IGNORE-DB: A database that is ignored when synchronizing
BINLOG-DO-DB: Specify the database that needs to be synchronized
1. After modifying the configuration, restart MySQL
Systemctl Restart MySQL
2, enter the Mysql,mysql-uroot-p, enter the MySQL password entered.
3, given from the library rights account, allowing users to read the log on the main library, give 192.168.0.4 that is slave machine has file permissions,
Only give slave machine has file permission not yet, also give it replication slave permission to be able.
FILE on *. * to ' root ' @ ' 192.168.0.4 ' identified by 'Root ' * * to ' root ' @ ' 192.168.0.4 ' identified by ' root ' ; Flush privileges;
The user here is the user that is used from the library when synchronizing.
4. Restart MySQL, log in to MySQL, view the main library information
Show master status;
If the command does not have data, it indicates that the configuration is incorrect.
File is used to synchronize the Binlog files, position is used when synchronizing.
Configuration of the Slave
1, modify the/ETC/MY.CNF
log-bin=mysql-binserver-id=3binlog-ignore-db=information_schemabinlog -ignore-db=clusterbinlog-ignore-db=mysqlreplicate-do-db= Testreplicate-ignore-db=mysqllog-slave-updatesslave-skip-errors= Allslave
2, can be seen here, in the version after mysql5.6 is not specified: And after the 5.6 version set the following content will be error
# Master's host IPmaster-user=rootmaster-password=mysql#
3, after modifying/etc/my.cnf, restart MySQL (systemctl restart MySQL)
Go to slave's MySQL console and do the following:
Stop Slave;change Master to master_host= ' 192.168.0.68 ', master_user= ' root ', master_password= ' root ', master_ Log_file= ' mysql-bin.000004 ', master_log_pos=28125; start slave;
Note: The above master_log_file is the file shown in master Show Master status,
Master_log_pos is the position shown in master Show Master status.
You can then view the configuration information through show slave status.
If the synchronization is not successful, see if position and file in show slave status correspond to the master.
mysql5.7 master-Slave (Master/slave) synchronization configuration