Mysql master-slave configuration

main: 192.168.0.42

1. Myini configuration

[mysql]
# Set the default character set of the mysql client
default-character-set=utf8 
[mysqld]
#Set 3306 port
port = 3306 
server_id=1
log_bin=mysqlmaster-bin
log_bin-index=mysqlmaster-bin.index
# Need to back up data, write multiple lines, and back up all without writing
binlog-do-db =userdb
#Do not need to back up the database, write multiple lines
#binlog-ignore-db = mysql 
# Set the installation directory of mysql
basedir =E:/NetCore advanced advanced/window-side common tools/ mysql - 8.0.11 - winx64
# Set the storage directory for the data of the mysql database
datadir =E:/NetCore advanced advanced/window-side common tools/ mysql-8.0.11 - winx64 / data
# maximum number of connections allowed
max_connections=200
# The character set used by the server defaults to the 8-bit encoded latin1 character set
character-set-server=utf8
# The default storage engine that will be used when creating new tables
default-storage-engine=INNODB
my.ini

2. Set synchronization account and permission assignment

1)GRANT FILE ON *.* TO 'testuser'@'192.168.0.73' IDENTIFIED BY '123456';
2) GRANT REPLICATION SLAVE ON *.* TO 'testuser'@'192.168.0.73' IDENTIFIED BY'123456'; 

3) Check the master server, the principle is actually to synchronize the database log files, the red box part needs to be used when setting the slave server

 

 

From: 192.168.0.73

1. Myini configuration

[mysql]
# Set the default character set of the mysql client
default-character-set=utf8 
[mysqld]
#Set 3306 port
port = 3306 
server_id=2 
log_bin=mysql-bin
log_bin-index=mysql-bin.index
# Need to back up data, write multiple lines, and back up all without writing
#binlog-do-db =z.userdb
#Do not need to back up the database, write multiple lines
#binlog-ignore-db = mysql 
#Tables that need to be synchronized
replicate-do-db=userdb
#No need to synchronize tables
replicate-ignore-db=mysql
# Set the installation directory of mysql
basedir=E:\mysql-5.7.22-winx64\mysql-5.7.22-winx64
# Set the storage directory for the data of the mysql database
datadir=E:\mysql-5.7.22-winx64\mysql-5.7.22-winx64/data
# maximum number of connections allowed
max_connections=200
# The character set used by the server defaults to the 8-bit encoded latin1 character set
character-set-server=utf8
# The default storage engine that will be used when creating new tables
default-storage-engine=INNODB
my.ini

2. Set the synchronization connection account and synchronization file location and other information

1) Stop the slave first: mysql>stop slave;

2 )执行:mysql>change master to master_host='192.168.0.42', master_user='test', master_password='123456',master_log_file='mysqlmaster-bin.000004',master_log_pos=154;

3) Start slave :mysql>start slave;

3. Check the status to see if there are any errors: mysql>show slave status; 

Possible errors: 1045 Error Configure the permissions under the synchronization account grant, check first

Then configure as needed

After completing these, you can do CQRS in the code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325256065&siteId=291194637
Recommended