MySQL master-slave database synchronization settings

MySQL master-slave database synchronization settings

1. Open the service item

Insert picture description here

Insert picture description here
Find the installation location
Insert picture description here
and make a copy
Insert picture description here

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
Insert picture description here
modify the port number :
Insert picture description here
Insert picture description here

Modify the address of the address of the slave database Modify the address
Insert picture description here
of the data storage of the slave database
Insert picture description here

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
Insert picture description here
, 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
Insert picture description here

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.
Insert picture description here
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
Insert picture description here

# 开启日志
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

Insert picture description here
Use the software to connect to the slave database,
Insert picture description here
you can see that there is data in the slave database, and the
Insert picture description here
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;

Insert picture description here
There will be an out_right authorized account in the user table
Insert picture description here

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

Insert picture description here

7.2 Setting from the database

Stop synchronization first and
stop SLAVE;
Insert picture description here
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;

Insert picture description here

Start synchronization:
START SLAVE;
Insert picture description here
view synchronization status
show SLAVE STATUS;

Insert picture description here

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
Insert picture description here

Insert picture description here
Restart the service and
Insert picture description here
inquire about the status:
stop slave;
start slave;
show slave status;

Insert picture description here

Guess you like

Origin blog.csdn.net/Guesshat/article/details/109384732