分类: LINUX
2018-09-05 09:11:55
第一mysql的双主环境:
首先是在之前的环境基础之上(mysql主从)继续进行配置
在MySQL主从搭建完成的基础上进行:
192.168.1.10(之前的主服务器,现在是服务器A)
192.168.1.20(之前的从服务器,现在是服务器B)
首先在服务器A上修改主配置文件:添加部分内容
log-bin=mysql-bin
binlog-do-db=kgcdb
binlog-ignore-db=mysql
read-only=0
auto-increment-increment=2
auto-increment-offset=1
log_slave_updates=on
server-id=1
重启服务
然后在服务器B上修改主配置文件:添加部分内容
log-bin=mysql-bin
binlog-do-db=kgcdb
binlog-ignore-db=mysql
read-only=0
auto-increment-increment=2
auto-increment-offset=2
log_slave_updates=on
server-id=2
重新启动MySQL服务。然后进入MySQL数据库
mysql> insert into mysql.user(Host,User,Password) values('localhost','bakuser1',password('123456'));
新建备份用户
grant replication slave on *.* to identified by '123456' with grant option;
授权
mysql> flush privileges;
刷新授权信息
mysql> show master status;
查看master状态
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000005 | 562 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
记住log日志名称和偏移量。
然后再回到服务器A:
mysql> slave stop;
mysql> change master to master_host='192.168.1.20', master_user='bakuser1', master_password='123456', master_log_file='mysql-bin.000005', master_log_pos=562;
mysql> slave start;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.20
Master_User: bakuser1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 902
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 593
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
最后,在服务器B上进行创建表的操作,然后到服务器A查看是否同步。