1. 程式人生 > >mysql 第四十五篇文章~初探MGR

mysql 第四十五篇文章~初探MGR

ini 擁有 bsp gtid_mode stat 執行 配置文件 不同 插入數據

一 簡介 :MGR一直沒有時間測試,今天咱們來初步了解搭建一下唄

二 環境: mysql5.7.20 單臺機器 啟動三實例

三 mysql 搭建:

1 建立相關目錄+

mkdir -p /data/mysql/data_3306

mkdir -p /data/mysql/data_3307

mkdir -p /data/mysql/data_3308

2 腳本初始化

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3306

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3307
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3308

3 修改密碼

mysql -uroot -S /tmp/mysql_3306.sock -e "set password for ‘root‘@‘localhost‘ = password(‘test‘);"

mysql -uroot -ptest -S /tmp/mysql_3306.sock -e "flush privileges"

mysql -uroot -S /tmp/mysql_3307.sock -e "set password for ‘root‘@‘localhost‘ = password(‘test‘);"
mysql -uroot -ptest -S /tmp/mysql_3307.sock -e "flush privileges"

mysql -uroot -S /tmp/mysql_3308.sock -e "set password for ‘root‘@‘localhost‘ = password(‘test‘);"
mysql -uroot -ptest -S /tmp/mysql_3308.sock -e "flush privileges"

4 啟動命令

nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3306.cnf &

nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3307.cnf &
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3308.cnf &

四 MGR配置

1 配置文件添加

gtid_mode = ON

enforce_gtid_consistency = ON

master_info_repository = TABLE
relay_log_info_repository = TABLE
binlog_checksum = NONE
log_slave_updates = ON
transaction_write_set_extraction = XXHASH64
loose-group_replication_group_name="01e5fb97-be64-41f7-bafd-3afc7a6ab555"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="127.0.0.1:13306"//除了此處不同 其他都相同
loose-group_replication_group_seeds="127.0.0.1:13306,127.0.0.1:13307,127.0.0.1:13308"
loose-group_replication_bootstrap_group = off

2 重啟服務,分別創建復制賬戶

set sql_log_bin=0;

GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repl‘@‘%‘ IDENTIFIED BY ‘repl‘;
flush privileges;
set sql_log_bin=1;

3 主節點執行

change master to master_user=‘repl‘,master_password=‘repl‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;
set global group_replication_bootstrap_group=ON;
START group_replication;
set global group_replication_bootstrap_group=OFF;

4 從節點執行

change master to master_user=‘repl‘,master_password=‘repl‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;
START group_replication;

5 查看狀態

select * from performance_schema.replication_group_members;

三個成員均為online 則代表搭建成功

6 查看主成員

1 select variable_value from performance_schema.global_status where variable_name =‘group_replication_primary_member‘; 獲取主UUID

2 select * from performance_schema.replication_group_members; 根據UUID確定primary

7 測試

1 建立一個擁有主鍵的表並插入數據(MGR架構下表必須擁有主鍵)

2 查看其他節點是否擁有數據

五 說明

這篇文章是單主的MGR的第一次嘗試,以後會繼續補充

mysql 第四十五篇文章~初探MGR