1. 程式人生 > >MySQL主主搭建

MySQL主主搭建

啟動 and sla set -s word const 權限 fse

1.在MySQL主從的基礎上修改:

#master1上

[mysqld]

server-id=101

log-bin = mysql-bin

auto-increment-increment = 2

auto-increment-offset = 1000

#master2上

[mysqld]

server-id=103

log-bin = mysql-bin

auto-increment-increment = 2

auto-increment-offset = 1001

2、分別為倆臺master創建各種的用戶供對方使用

#master1的機器上
mysql> CREATE USER ‘master1‘@‘%‘ IDENTIFIED BY ‘123456‘;

#master2的機器上
mysql> CREATE USER ‘master2‘@‘%‘ IDENTIFIED BY ‘123456‘; 

3、分別給用戶授予復制權限

#master1的機器上
mysql> GRANT REPLICATION SLAVE  ON *.* TO ‘master1‘@‘%‘ IDENTIFIED BY ‘123456‘;

#master2的機器上
mysql> GRANT REPLICATION SLAVE  ON *.* TO ‘master2‘@‘%‘ IDENTIFIED BY ‘123456‘;

4、分別重啟服務,通過show master status 查看二進制文件名稱還有pos位置,為slave配置復制位置

5.分別切換master,註意master_log_file還有master_log_pos

#master1的機器上

mysql> change master to master_host=‘192.168.137.103‘,master_user=‘master2‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000003‘,master_log_pos=951;

#master2的機器上

mysql> change master to master_host=‘192.168.137.101‘,master_user=‘master1‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000004‘,master_log_pos=698;

6.然後啟動驗證:

start slave

ok!!!!!!!

MySQL主主搭建