MySQL master-slave database synchronization and precautions under windows

Master-slave server principle

tool: two mysql databases such as: 192.168.1.1 (master) and 192.168.1.2 (slave)
start configuration
1
: Modify the master database my.ini configuration (click the software to open the location) Server-id = 1 (Initial configuration does not have this, add it manually)
log-bin = mysql-synchronous-log binary log file, required, otherwise the data cannot be synchronized; if no name is given, the binary file will be named after the computer's name and number (On the Internet, I haven't tried how to name myself, it is recommended to set the name by yourself)
binlog-do-db = test-table Database that needs to be synchronized, if there are multiple libraries that need to be synchronized, separate them with commas and add them one by one. If not written, the default is all Library
binlog-ignore-db = ignore-table Databases that do not need to be synchronized, the rules are the same as above Restart the MySQL service after
modification 2: Add a synchronized account to the master database, and use the execution command
when adding a master-slave relationship from the server
: grant replication slave, file on *.* to 'slave'@'%' identified by '123456';
three: check synchronization information
and execute the command under mysql: show master status; you can query the log file name and position
four: configure my. ini
is similar to configuring the main database, but log-bin does not need to be configured
5
: Execute the command from MySQL to link the main server 1: Execute the slave stop command first to stop the slave service
2: mysql> change master to
       -> master_host='192.168.1.1',
       -> master_user='slave',
       -> master_password='123456',
       -> master_log_file='mysql-synchronous-log.000040', (step 3 The log name queried)
       -> master_log_pos=107; (Position queried in step 3)
will prompt "Query OK, 0 rows affected" after success.
3: Execute the slave start command to start the service. After success, it will prompt "Query OK, 0 rows affected"
Six: Verify whether the master-slave configuration is successful
and finally use show slave status\G; check the status of Slave_IO_Running and Slave_SQL_Running, if both are Yes, it is successful
Note
: ①: Server-id This is the database ID. This ID is unique. The ID value cannot be repeated, otherwise a synchronization error will occur.
②: Every time the configuration file is modified, it must be restarted
. The result is consistent
④: If you want to be specific to a table in a library, you can add replicate-wild-ignore-table=test-table in the slave server configuration.
⑤: If you can't link to the main database, you need to see if the bind 127.0.0.1 in my.ini in the main database is not commented. If not, you can only log in locally instead of using the remote login method (seen in other people's articles). , not tested)
⑥If the modified configuration file is invalid after restarting, you can view the properties of the mysql service in the service, --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" mysql service reads The configuration file is here, modify my.ini in this path, restart the service, and the configuration will take effect.

Guess you like

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