title: Windows配置mysql主主复制
date: 2019-09-21 10:40:02
tags: MySQL
因为主主复制是两台数据库互为主从,所以接着上一主从配置继续:
原主库(3306)配置文件中加入:
auto-increment-offset=1 #起始值。一般填第n台主MySQL。此时为第一台主MySQL
auto-increment-increment=2 #步进值auto_imcrement。一般有n台主MySQL就填n
原从库(3307)配置文件中加入:
auto-increment-offset=2
auto-increment-increment=2
# 说明:
服务器 3306端口 自增列显示为:1,3,5,7,……(offset=1,increment=2)
服务器 3307端口 自增列显示为:2,4,6,8,……(offset=2,increment=2)
1. 在端口3307的中mysql配置
create user 'root'@'127.0.0.1' identified by 'root';
grant replication slave on *.* to 'root'@'127.0.0.1';
flush privileges;
show master status;
#记住File下的值和Position的值。
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 2922 | dongyi | mysql | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2.在端口3306的mysql配置
CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_PORT=3307,MASTER_USER='root',MASTER_PASSWORD='root',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=2922;
mysql>start slave; #开启slave同步进程
# 查看slave状态
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 127.0.0.1
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2922
Relay_Log_File: MY-20190430BUDR-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
...
补充:
创建用户,并授予权限:
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
grant all privileges on *.* to 'root'@'%';
flush privileges;
公众号:一丁点技术