通过MySQL router连接MySQL8.0.23 Group Replication使用方式
服务器信息:
应用服务器:部署Myrouter,版本mysql-router-8.0.23-linux-glibc2.17-x86_64-minimal
10.172.144.88
10.172.144.89
数据库服务器:部署MGR,版本mysql-8.0.23-linux-glibc2.17-x86_64-minimal
10.172.144.65
10.172.144.66
10.172.144.67
1、MySQL8.0.23 Group Replication集群配置情况:
[mysql@p0-db01 ~]$ mysqlsh root@p0-db01:3306
MySQL Shell 8.0.23
Copyright (c) 2016, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@p0-db01:3306'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 22518087
Server version: 8.0.23 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL p0-db01:3306 ssl JS > var cluster=dba.getCluster()
MySQL p0-db01:3306 ssl JS > cluster.status()
{
"clusterName": "MySQLCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "p0-db01:3306",
"ssl": "REQUIRED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"p0-db01:3306": {
"address": "p0-db01:3306",
"mode": "R/W",
"readReplicas": {},
"replicationLag": null,
"role": "HA",
"status": "ONLINE",
"version": "8.0.23"
},
"p0-db02:3306": {
"address": "p0-db02:3306",
"mode": "R/O",
"readReplicas": {},
"replicationLag": null,
"role": "HA",
"status": "ONLINE",
"version": "8.0.23"
},
"p0-db03:3306": {
"address": "p0-db03:3306",
"mode": "R/O",
"readReplicas": {},
"replicationLag": null,
"role": "HA",
"status": "ONLINE",
"version": "8.0.23"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "p0-db01:3306"
}
MySQL p0-db01:3306 ssl JS >
2、应用使用MySQL8.0.23 MGR集群的方式,分为读写业务、只读业务
#读写业务应用,采用6446端口
[sysadm@p0-app01 ~]$ mysql -uadmin -p'123456' -h 10.172.144.88 -P 6446 -e "select @@hostname"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------+
| @@hostname |
+---------------------+
| p0-db01 |
+---------------------+
群集的状态如下
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+---------------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+---------------------+-------------+--------------+-------------+----------------+
| group_replication_applier | e09a9596-01bd-11ed-b9f6-005056a4f70c | p0-db01 | 3306 | ONLINE | PRIMARY | 8.0.23 |
| group_replication_applier | e1a5a444-01bd-11ed-9100-005056a47247 | p0-db02 | 3306 | ONLINE | SECONDARY | 8.0.23 |
| group_replication_applier | e23aaccc-01bd-11ed-86e5-005056a4f766 | p0-db03 | 3306 | ONLINE | SECONDARY | 8.0.23 |
+---------------------------+--------------------------------------+---------------------+-------------+--------------+-------------+----------------+
3 rows in set (0.00 sec)
#只读业务应用,采用6447端口
[sysadm@p0-app01 ~]$ mysql -uadmin -p'123456' -h 10.172.144.88 -P 6447 -e "select @@hostname"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------+
| @@hostname |
+---------------------+
| p0-db02 |
+---------------------+
[sysadm@p0-app01 ~]$ mysql -uadmin -p'123456' -h 10.172.144.88 -P 6447 -e "select @@hostname"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------+
| @@hostname |
+---------------------+
| p0-db03 |
+---------------------+
[sysadm@p0-app01 ~]$ mysql -uadmin -p'123456' -h 10.172.144.88 -P 6447 -e "select @@hostname"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------+
| @@hostname |
+---------------------+
| p0-db02 |
+---------------------+
[sysadm@p0-app01 ~]$
多次查询结果显示,不同的连接连接到不通的主库数据库