Currently: D:\mysql-5.7.25 ( as the master library ) -> D:\mysql-5.7.25-FDB ( as the slave library )
step one:
First modify the my.ini configuration file from the database
[mysqld]
#Set
port 3307
_
port
=
3307
#Set
the
installation directory of
mysql
basedir
=
D:\mysql-5.7.25-FDB
#Set
the
data storage directory of the
mysql database
datadir
=
D:\mysql-5.7.25-FDB\data
Then open the cmd command in the bin directory of the slave library and enter
-defaults-file
=
"
D:\mysql-5.7.25-FDB\my.ini
" (this is to install the library under windows)
Step two:
Modify the relevant configuration of the master-slave database
Master database-my.ini:
[mysqld]
#Open
log
log‐bin
=
mysql‐bin
#Set
the service
id
, the master and slave cannot be consistent
server‐id
=
1
#Set
the database that needs to be synchronized
binlog‐do‐db
=
course
#
Shield system library synchronization
binlog‐ignore‐db
=
mysql
binlog‐ignore‐db
=
information_schema
binlog‐ignore‐db
=
performance_schema
From database-my.ini:
[mysqld]
#Open
log
log‐bin
=
mysql‐bin
#Set
the service
id
, the master and slave cannot be consistent
server‐id
=
2
#Set
the database that needs to be synchronized
replicate_wild_do_table
=
course.%
#
Shield system library synchronization
replicate_wild_ignore_table
=
mysql.%
replicate_wild_ignore_table
=
information_schema.%
replicate_wild_ignore_table
=
performance_schema.%
Step three:
Create an account for master-slave replication
#Switch
to
the bin
directory of the main library and log in to the main library
mysql
‐h
localhost
‐uroot ‐p
#Authorize
the dedicated account for master and backup replication
GRANT REPLICATION SLAVE ON *.* TO
'db_sync'
@
'%'
IDENTIFIED BY
'db_sync'
;
#
Refresh permissions
FLUSH PRIVILEGES;
#Confirm
the location and record the file name and location
show master status;
Step four:
Set up data synchronization from the library to the main library
#Switch
to the
bin
directory of the slave library and log in to the slave library
mysql
‐h
localhost
‐P3307 ‐uroot ‐p
#
first stop synchronization
STOP SLAVE;
#Modify
the slave library pointing to the main library, using the file name and location recorded in the previous step
CHANGE MASTER TO
master_host
=
'localhost'
,
master_user
=
'db_sync'
,
master_password
=
'db_sync'
,
#The following two data are the data information obtained in step 3 to determine the location
master_log_file
=
'mysql‐bin.000002'
,
master_log_pos
=
154
;
#
start synchronization
START SLAVE;
#View
slave library status
Slave_IO_Runing
and
Slave_SQL_Runing
are both
Yes
, indicating that the synchronization is successful, if not
Yes
, please check
error_log
, then
Check for related exceptions.
show slave status
#Note
that if the slave library has already pointed to the main library before, you need to execute the following command to clear it first
STOP SLAVE IO_THREAD FOR CHANNEL
''
;
reset slave all;