MySQL master-slave database synchronization settings
1. Open the service item
Find the installation location
and make a copy
2. Modify the mini file from the database
It may not be found. This is because if the default installation is used, the files will be stored in the hidden folder. You need to set the file display hidden file settings yourself.
Then find the mysql folder under the programData folder and copy a copy to
modify the port number :
Modify the address of the address of the slave database Modify the address
of the data storage of the slave database
3. Install from the database
Enter the bin directory of the slave database and open the command window.
Enter the command:
mysqld install mysql-back --defaults-file= "C:\ProgramData\MySQL\MySQL Server 5.7-back\my.ini"
the file address of my.ini is specified later. Modify it according to your own. If the
installation is successful
, refresh it in the service and check it. This is just the installation of the data, and it is not started. Follow-up Also need to be configured, and finally start
4. Modify the my.ini of the master database and the slave database to associate
Modification of the main database
# 开启日志
log-bin=mysql-bin
Check the server-id of the primary database, and the secondary database should not have the same configuration as the primary database.
Set the database you want to synchronize and shield the system database
# 设置需要同步的数据库
binlog-do-db=temporary
# 屏蔽系统库同步
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
Modify from the database
server-id=2
# 开启日志
log-bin=mysql-bin
# 设置需要同步的数据库
replicate_wild_do_table=temporary.%
# 屏蔽系统库同步
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=information_schema.%
replicate_wild_ignore_table=performance_schema.%
5. Restart the master-slave database
Use the software to connect to the slave database,
you can see that there is data in the slave database, and the
data is not synchronized at this time, because there is no permission, you need to authorize and set up in the master database
6. Authorization settings
GRANT REPLICATION SLAVE ON *.* TO '新建账户名'@'%'IDENTIFIED BY '新建的账户名(作为密码使用)';
Refresh
FLUSH PRIVILEGES;
There will be an out_right authorized account in the user table
7. Turn on synchronization
The above operation just allows the slave database and the master database to have the same data structure, but the data is not synchronized when inserting and deleting the data table. The following is the data synchronization setting
7.1 View the data status of the main database
show master status
The values of File and Position running under the master database need to be used in the settings of the slave database
7.2 Setting from the database
Stop synchronization first and
stop SLAVE;
run from the database
Connect to the main database to prepare for synchronization
CHANGE MASTER TO
# 主数据库地址
MASTER_HOST = 'localhost',
#授权的用户名和密码
MASTER_USER = 'out_right',
MASTER_PASSWORD = 'out_right',
#刚才查询的主数据库信息
MASTER_log_file = 'mysql-bin.000001',
MASTER_log_pos = 446;
Start synchronization:
START SLAVE;
view synchronization status
show SLAVE STATUS;
6.3 The difference is resolved by yes
Because the file auto.cnf in the slave database is directly assigned to the master database, there is a conflict, delete the auto.cnf file in the slave database, and restart the slave database
Restart the service and
inquire about the status:
stop slave;
start slave;
show slave status;