Windows same server mysql master-slave configuration mode

Mysql master-slave library configuration method
First download the mysql database green installation package ( download address ), decompress it into two copies, one is the mysql master library (D:/mysql/mysql5.6.17), and the other is the mysql slave library (D:/ mysql/mysql5.6.17_slave)

[1], the main library my.ini configuration information

server-id	= 1
port=3306
basedir=D:/mysql/mysql5.6.17
datadir=D:/mysql/mysql5.6.17/data
explicit_defaults_for_timestamp = TRUE
binlog-do-db=test 
#binlog-do-db=需要复制的数据库名,如果复制多个数据库,重复设置这个选项即可
#binlog-ignore-db=不需要复制的数据库名,如果不需要复制多个数据库,重复设置这个选项即可

[1.1], open cmd, first (cd) enter the bin directory of the main library, and then use the command to install the main library service:

mysqld install mysql1 --defaults-file="D:\mysql\mysql5.6.17\my.ini

[1.2], go to [Control Panel] -> [Service] to start the main database service
[1.3], first use the command to connect to the main database:

mysql -uroot -p -P3306   

[1.4] Create a synchronous user

create user 'syncuser'@'127.0.0.1' identified by '123456';

[1.5] Assign synchronization user permissions

grant replication slave on *.* to 'syncuser'@'127.0.0.1' identified by '123456';

[1.6], through the command: show master status, check the status of the master library (query fields: File and Position, these two fields correspond to the command parameters master_log_file and master_log_pos in [3.4] respectively)

[2] Configuration information from library my.ini
Configuration information from library my.ini

[mysqld]
port= 3307
basedir=D:/mysql/mysql5.6.17_slave
datadir=D:/mysql/mysql5.6.17_slave/data
skip-slave-start
server-id = 2

[2.1] Open cmd, first (cd) enter the bin directory of the main library, and then use the command to install the service from the library:

mysqld install mysql2 --defaults-file="D:\mysql\mysql5.6.17_slave\my.ini

[3], configure the master-slave settings
[3.1], first modify the uuid in auto.cnf in the data directory of the slave library (make sure the number of uuid is 36 bits) (or delete it directly, with the one that starts the slave library service Automatically generated at time) (to prevent repeated uuid errors)
[3.2], go to [Control Panel] -> [Service] to start the database service
[3.3], first use the command to connect to the slave library:

mysql -uroot -p -P3307

[3.4] After the connection is successful, enter the command,

mysql>change master to master_host='127.0.0.1',master_port=3306,master_user='syncuser',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=498; 

[3.5], start the master-slave replication function, enter the command:

start slave;

[3.6], check the status of the slave library, enter the command:

mysql>show slave status;

If both Slave_IO_Running | Slave_SQL_Running field values ​​are yes, the configuration is successful.

-----If there is a problem with the configuration, you can view the log ending with err in the data under the library mysql2

[4] Test verification
[4.1] Execute the database creation script on the main database

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `account` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
INSERT INTO `user` VALUES (1, 'user1', 'user1', 'user1');
INSERT INTO `user` VALUES (2, 'user2', 'user2', 'user2');
INSERT INTO `user` VALUES (3, 'user3', 'user3', 'user3);

[4.2] Check whether the user table is created at the same time from the slave database. If the creation is successful and the same data as the master database is added, it means that the master-slave synchronization setting is successful

【5】、Notes on configuration:
The configuration method of binlog_do_db, if there are multiple databases to be synchronized, the configuration method is
binlog_do_db=database1
binlog_do_db=database2
If binlog_do_db is not set, all databases will be synchronized through binlog-ignore-db Exclude out-of-sync databases

show master status: View the status of the master library (query fields: File and Position)

skip-slave-start: The slave library replication process does not start with mysql startup
(that is to say, after the main library is restarted, the original slave library will re-copy the original main library, which will cause the synchronized data to be synchronized again and cause conflicts )

【6】、Related command statement
Install mysql service command

mysqld install mysql2 --defaults-file="D:\mysql\mysql5.6.17_slave\my.ini

Delete database service command

sc delete mysql2 -- 这里的mysql是你要删除的服务名

Configure the master-slave command (the File and Position of the master library correspond to the parameters master_log_file and mast_log_pos respectively)

change master to master_host='127.0.0.1',master_port=3306,master_user='mytest',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=498;

Turn on the function of copying from the library

start slave;

Stop the master-slave replication function

stop slave;

View the master status of the main library

show masterstatus;

View slave status from library

show slave status;

Guess you like

Origin blog.csdn.net/teamo_m/article/details/105783416