Master: 192.168.0.42
1. Myini Configuration
[mysql]# set MySQL client default character setdefault-character-Set=UTF8 [mysqld] #设置3306端口port=3306server_id=1Log_bin=mysqlmaster-Binlog_bin-index=mysqlmaster-bin.index# need to back up data, multiple write multiple lines, not write all backup Binlog- Do-db =userdb# A database that does not need to be backed up, multiple write multiple lines #binlog-ignore-db =MySQL # set up MySQL installation directory Basedir=e:/netcore Advanced/window-end common tools/mysql-8.0. One-winx64# Set the data storage directory for the MySQL database DataDir=e:/netcore Advanced/window-end common tools/mysql-8.0. One-winx64/data# Maximum number of connections allowed Max_connections= $# The default character set used by the server is a 8-bit encoded latin1 character Set character-Set-server=utf8# default storage engine to use when creating a new tabledefault-storage-engine=innodb
My.ini
2. Set up sync account and rights 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) View the main server, the principle is to synchronize the database log files, the Red box section in the settings from the server needs to use
From: 192.168.0.73
1. Myini Configuration
[mysql]# set MySQL client default character setdefault-character-Set=UTF8 [mysqld] #设置3306端口port=3306server_id=2Log_bin=mysql-Binlog_bin-index=mysql-bin.index# need to back up data, multiple write multiple lines, not write all backup #binlog- Do-db =z.userdb# A database that does not need to be backed up, multiple write multiple lines #binlog-ignore-db =MySQL #需要同步的表replicate- Do-db=userdb# tables that do not need to be synchronized replicate-ignore-db=mysql# Set the installation directory for MySQL Basedir=e:\mysql-5.7. A-winx64\mysql-5.7. A-winx64# Set the data storage directory for the MySQL database DataDir=e:\mysql-5.7. A-winx64\mysql-5.7. A-winx64/data# Maximum number of connections allowed Max_connections= $# The default character set used by the server is a 8-bit encoded latin1 character Set character-Set-server=utf8# default storage engine to use when creating a new tabledefault-storage-engine=innodb
My.ini
2, set up sync Connection account and sync file location and other information
1) Stop the slave:mysql>stop slave first;
2) Execution: 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 state to see if there is error: mysql>show slave status;
Errors that may occur: 1045 Error Configuration Sync account grant under Permissions, first check the next
Then configure as needed
When you're done, you can do CQRS in your code.
Use in Dotnetcore projects
dotnet EF Migrations Add initdatabase
dotnet EF Database Update
Initializing the database, you can see that the server has synchronized
Mysql Master-Slave configuration