参考文档:5.7的参考文档没有看,本次测试主要看8.0的参考文档
(KB378603)Getting Started with MySQL 5.7 InnoDB Cluster - How to Set Up a Cluster from Scratch?
(KB664116)How to Set Up a MySQL 8.0 InnoDB Cluster from Scratch?
在同一台机器上测试安装Innodb Cluster(其实就是MGR),使用工具mysql shell。
之前的安装方式,先安装mgr,然后通过mysql shell接管mgr。现在的安装方式,直接安装,在安装的过程中,会clone生成mgr 。
OS Kernel : 5.15.0-322.203.3.4.el8uek.x86_64
mysql版本:mysql-8.4.10-linux-glibc2.28-x86_64.tar.xz
mysql shell版本 : mysql-shell-9.7.1-1.el8.x86_64.rpm
mysql router版本:mysql-router-community-9.7.1-1.el8.x86_64.rpm 。这三个软件,是安装在同一台测试机器上。
三个mysql分别安装在mysql01、mysql02、mysql03目录下
[root@innodb-cluster01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.8G 0 2.8G 0% /dev
tmpfs 2.8G 0 2.8G 0% /dev/shm
tmpfs 2.8G 8.7M 2.8G 1% /run
tmpfs 2.8G 0 2.8G 0% /sys/fs/cgroup
/dev/mapper/ol-root 17G 4.7G 13G 28% /
/dev/sdb1 30G 4.1G 26G 14% /mysql01
/dev/sdc1 20G 2.8G 18G 14% /mysql02
/dev/sda1 1014M 417M 598M 42% /boot
/dev/sdd1 20G 2.8G 18G 14% /mysql03
tmpfs 561M 0 561M 0% /run/user/0
[root@innodb-cluster01 ~]#
--- 初始化mysql01
[root@innodb-cluster01 bin]# ./mysqld --initialize --console
2026-07-18T02:36:31.489326Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2026-07-18T02:36:31.491711Z 0 [System] [MY-013169] [Server] /mysql01/mysql-8.4.10-linux-glibc2.28-x86_64/bin/mysqld (mysqld 8.4.10) init7
2026-07-18T02:36:31.499971Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-07-18T02:36:32.001695Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-07-18T02:36:32.533697Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: O;(yl&Zc+4#c
2026-07-18T02:36:33.977509Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
[root@innodb-cluster01 bin]#
-- mysql01的my.cnf文件(只保留测试使用的最小的参数)
[root@innodb-cluster01 ~]# more /mysql01/mysql330601/my.cnf
[mysqld]
#
# Disable other storage engines
#
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
#
# Replication configuration parameters
#
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON
port=3306
socket = /tmp/mysql3306.sock
mysqlx_port = 33061 # X Protocol 端口也改掉
mysqlx_socket = /tmp/mysqlx3306.sock
#
# Group Replication configuration
#
plugin_load_add='group_replication.so'
group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
group_replication_start_on_boot=off
group_replication_local_address= "localhost:23061"
group_replication_group_seeds= "localhost:23061,localhost:23062,localhost:23063"
group_replication_bootstrap_group= off
[root@innodb-cluster01 ~]#
--初始化mysql02
./mysqld --initialize --console
[root@innodb-cluster01 bin]# pwd
/mysql02/mysql330602/bin
[root@innodb-cluster01 bin]# ./mysqld --initialize --console
2026-07-18T02:52:53.247263Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2026-07-18T02:52:53.249975Z 0 [System] [MY-013169] [Server] /mysql02/mysql330602/bin/mysqld (mysqld 8.4.10) initializing of server in pr4
2026-07-18T02:52:53.260961Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-07-18T02:52:53.855069Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-07-18T02:52:54.514020Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _C+gHko=7tUy
2026-07-18T02:52:56.539798Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
-- mysql02的my.cnf文件(只保留测试使用的最小的参数)
[root@innodb-cluster01 ~]# more /mysql02/mysql330602/my.cnf
[mysqld]
#
# Disable other storage engines
#
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
#
# Replication configuration parameters
#
server_id=2
gtid_mode=ON
enforce_gtid_consistency=ON
port=3307
socket = /tmp/mysql3307.sock
mysqlx_port = 33071 # X Protocol 端口也改掉
mysqlx_socket = /tmp/mysqlx3307.sock
#
# Group Replication configuration
#
plugin_load_add='group_replication.so'
group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
group_replication_start_on_boot=off
group_replication_local_address= "localhost:23062"
group_replication_group_seeds= "localhost:23061,localhost:23062,localhost:23063"
group_replication_bootstrap_group= off
[root@innodb-cluster01 ~]#
-- 初始化mysql03
[root@innodb-cluster01 bin]# pwd
/mysql03/mysql330603/bin
[root@innodb-cluster01 bin]# ./mysqld --initialize --console
2026-07-18T03:09:22.011286Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2026-07-18T03:09:22.015909Z 0 [System] [MY-013169] [Server] /mysql03/mysql330603/bin/mysqld (mysqld 8.4.10) initializing of server in pr6
2026-07-18T03:09:22.026685Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-07-18T03:09:22.589812Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-07-18T03:09:23.271249Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vhLjBuitM8-7
2026-07-18T03:09:25.279028Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
[root@innodb-cluster01 bin]#
-- mysql03的my.cnf文件(只保留测试使用的最小的参数)
[root@innodb-cluster01 ~]# more /mysql03/mysql330603/my.cnf
[mysqld]
#
# Disable other storage engines
#
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
#
# Replication configuration parameters
#
server_id=3
gtid_mode=ON
enforce_gtid_consistency=ON
port=3308
socket = /tmp/mysql3308.sock
mysqlx_port = 33081 # X Protocol 端口也改掉
mysqlx_socket = /tmp/mysqlx3308.sock
#
# Group Replication configuration
#
plugin_load_add='group_replication.so'
group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
group_replication_start_on_boot=off
group_replication_local_address= "localhost:23063"
group_replication_group_seeds= "localhost:23061,localhost:23062,localhost:23063"
group_replication_bootstrap_group= off
[root@innodb-cluster01 ~]#
-- 在mysqlshell中创建innodb cluster, mysqlshell连接到节点1 .每个节点都要。不然后面继续操作的时候,发现没有账号 。
[root@innodb-cluster01 mysql01]# mysqlsh -uroot -h127.0.0.1 -p -P3306
Please provide the password for 'root@127.0.0.1:3306': *****
Save password for 'root@127.0.0.1:3306'? [Y]es/[N]o/Ne[v]er (default No): Y
MySQL Shell 9.7.1
Copyright (c) 2016, 2026, 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@127.0.0.1:3306'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 10
Server version: 8.4.10 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL 127.0.0.1:3306 ssl SQL >
--对于每个实例,使用 dba.checkInstanceConfiguration() 方法验证其是否已正确配置为 InnoDB 集群:
dba.configureInstance("root@localhost:3306")
dba.configureInstance("root@localhost:3307")
dba.configureInstance("root@localhost:3308")
-- mysql3306上验证,并创建账号
MySQL 127.0.0.1:3306 ssl SQL > \js
Switching to JavaScript mode...
MySQL 127.0.0.1:3306 ssl JS > dba.configureInstance("root@localhost:3306")
Please provide the password for 'root@localhost:3306': *****
Save password for 'root@localhost:3306'? [Y]es/[N]o/Ne[v]er (default No): Y
Configuring local MySQL instance listening at port 3306 for use in an InnoDB Cluster...
This instance reports its own address as innodb-cluster01:3306
Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQ.
ERROR: User 'root' can only connect from 'localhost'. New account(s) with proper source address specification to allow remote connection.
1) Create remotely usable account for 'root' with same grants and password
2) Create a new admin account for InnoDB Cluster with minimal required grants
3) Ignore and continue
4) Cancel
Please select an option [1]: 2
Please provide an account name (e.g: icroot@%) to have it created with the necessary
privileges or leave empty and press Enter to cancel.
Account Name: icadmin@%
Password for new account: *****
Confirm password: *****
applierWorkerThreads will be set to the default value of 4.
Creating user icadmin@%.
Account icadmin@% was successfully created.
The instance 'innodb-cluster01:3306' is valid for InnoDB Cluster usage.
Successfully enabled parallel appliers.
MySQL 127.0.0.1:3306 ssl JS >
-- 连接到3307上验证,并创建账号
dba.configureInstance("root@localhost:3307")
[root@innodb-cluster01 mysql01]# mysqlsh -uroot -h127.0.0.1 -p -P3307
Please provide the password for 'root@127.0.0.1:3307': *****
Save password for 'root@127.0.0.1:3307'? [Y]es/[N]o/Ne[v]er (default No): Y
MySQL Shell 9.7.1
Copyright (c) 2016, 2026, 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@127.0.0.1:3307'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 18
Server version: 8.4.10 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL 127.0.0.1:3307 ssl SQL > \js
Switching to JavaScript mode...
MySQL 127.0.0.1:3307 ssl JS > dba.configureInstance("root@localhost:3307")
Configuring local MySQL instance listening at port 3307 for use in an InnoDB Cluster...
This instance reports its own address as innodb-cluster01:3307
Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQ.
ERROR: User 'root' can only connect from 'localhost'. New account(s) with proper source address specification to allow remote connection.
1) Create remotely usable account for 'root' with same grants and password
2) Create a new admin account for InnoDB Cluster with minimal required grants
3) Ignore and continue
4) Cancel
Please select an option [1]: 2
Please provide an account name (e.g: icroot@%) to have it created with the necessary
privileges or leave empty and press Enter to cancel.
Account Name: icadmin@%
Password for new account: *****
Confirm password: *****
applierWorkerThreads will be set to the default value of 4.
Creating user icadmin@%.
Account icadmin@% was successfully created.
The instance 'innodb-cluster01:3307' is valid for InnoDB Cluster usage.
Successfully enabled parallel appliers.
MySQL 127.0.0.1:3307 ssl JS >
--连接到3308上验证,并创建账号
dba.configureInstance("root@localhost:3308")
[root@innodb-cluster01 mysql01]# mysqlsh -uroot -h127.0.0.1 -p -P3308
Please provide the password for 'root@127.0.0.1:3308': *****
Save password for 'root@127.0.0.1:3308'? [Y]es/[N]o/Ne[v]er (default No): Y
MySQL Shell 9.7.1
Copyright (c) 2016, 2026, 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@127.0.0.1:3308'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 11
Server version: 8.4.10 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL 127.0.0.1:3308 ssl SQL > \js
Switching to JavaScript mode...
MySQL 127.0.0.1:3308 ssl JS > dba.configureInstance("root@localhost:3308")
Configuring local MySQL instance listening at port 3308 for use in an InnoDB Cluster...
This instance reports its own address as innodb-cluster01:3308
Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQ.
ERROR: User 'root' can only connect from 'localhost'. New account(s) with proper source address specification to allow remote connection.
1) Create remotely usable account for 'root' with same grants and password
2) Create a new admin account for InnoDB Cluster with minimal required grants
3) Ignore and continue
4) Cancel
Please select an option [1]: 2
Please provide an account name (e.g: icroot@%) to have it created with the necessary
privileges or leave empty and press Enter to cancel.
Account Name: icadmin@%
Password for new account: *****
Confirm password: *****
applierWorkerThreads will be set to the default value of 4.
Creating user icadmin@%.
Account icadmin@% was successfully created.
The instance 'innodb-cluster01:3308' is valid for InnoDB Cluster usage.
Successfully enabled parallel appliers.
MySQL 127.0.0.1:3308 ssl JS >
--连接到3306上 创建cluster,要使用上面创建的用户icadmin@%来连接
[root@innodb-cluster01 mysql01]# mysqlsh -uicadmin -h127.0.0.1 -p -P3306
Please provide the password for 'icadmin@127.0.0.1:3306': *****
Save password for 'icadmin@127.0.0.1:3306'? [Y]es/[N]o/Ne[v]er (default No): Y
MySQL Shell 9.7.1
Copyright (c) 2016, 2026, 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 'icadmin@127.0.0.1:3306'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 15
Server version: 8.4.10 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL 127.0.0.1:3306 ssl SQL > dba.createCluster("myCluster");
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right 1
MySQL 127.0.0.1:3306 ssl SQL > \js
Switching to JavaScript mode...
MySQL 127.0.0.1:3306 ssl JS > dba.createCluster("myCluster");
A new InnoDB Cluster will be created on instance 'innodb-cluster01:3306'.
Validating instance configuration at 127.0.0.1:3306...
This instance reports its own address as innodb-cluster01:3306
Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'innodb-cluster01:3306'. Use the localAddress option to override.
* Checking connectivity and SSL configuration...
Creating InnoDB Cluster 'myCluster' on 'innodb-cluster01:3306'...
Adding Seed Instance...
Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
At least 3 instances are needed for the cluster to be able to withstand up to
one server failure.
<Cluster:myCluster>
MySQL 127.0.0.1:3306 ssl JS
-- 添加剩余的两个节点到cluster集群中
cluster.addInstance('icadmin@localhost:3307');
cluster.addInstance('icadmin@localhost:3308');
--连接到3306上,把3307添加到集群,可以看到使用到了clone技术
[root@innodb-cluster01 mysql01]# mysqlsh -uicadmin -h127.0.0.1 -p -P3306
Please provide the password for 'icadmin@127.0.0.1:3306': *****
Save password for 'icadmin@127.0.0.1:3306'? [Y]es/[N]o/Ne[v]er (default No): Y
MySQL Shell 9.7.1
Copyright (c) 2016, 2026, 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 'icadmin@127.0.0.1:3306'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 53
Server version: 8.4.10 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL 127.0.0.1:3306 ssl SQL > \js
Switching to JavaScript mode...
MySQL 127.0.0.1:3306 ssl JS > var cluster = dba.getCluster("myCluster");
MySQL 127.0.0.1:3306 ssl JS > cluster.addInstance('icadmin@localhost:3307');
WARNING: A GTID set check of the MySQL instance at 'innodb-cluster01:3307' determined that it contains transactions that do not originat.
Instance 'innodb-cluster01:3307' has the following errant GTIDs that do not exist in the cluster:
c57f918e-8253-11f1-8af0-000c2951f167:1
WARNING: Discarding these extra GTID events can either be done manually or by completely overwriting the state of 'innodb-cluster01:3307.
Having extra GTID events is not expected, and it is recommended to investigate this further and ensure that the data can be removed prio.
Please select a recovery method [C]lone/[A]bort (default Abort): C
Validating instance configuration at localhost:3307...
This instance reports its own address as innodb-cluster01:3307
Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'innodb-cluster01:3307'. Use the localAddress option to override.
* Checking connectivity and SSL configuration...
A new instance will be added to the InnoDB Cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.
Adding instance to the cluster...
Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
Clone based state recovery is now in progress.
NOTE: A server restart is expected to happen as part of the clone process. If the
server does not support the RESTART command or does not come back after a
while, you may need to manually start it back.
* Waiting for clone to finish...
NOTE: innodb-cluster01:3307 is being cloned from innodb-cluster01:3306
** Stage DROP DATA: Completed
** Clone Transfer
FILE COPY ############################################################ 100% Completed
PAGE COPY ############################################################ 100% Completed
REDO COPY ############################################################ 100% Completed
* Clone process has finished: 77.09 MB transferred in about 1 second (~77.09 MB/s)
State recovery already finished for 'innodb-cluster01:3307'
The instance 'innodb-cluster01:3307' was successfully added to the cluster.
MySQL 127.0.0.1:3306 ssl JS >
-- 连接到3306上,把3308添加上去,可以看到,使用到了clone技术
MySQL 127.0.0.1:3306 ssl JS >
MySQL 127.0.0.1:3306 ssl JS > cluster.addInstance('icadmin@localhost:3308');
WARNING: A GTID set check of the MySQL instance at 'innodb-cluster01:3308' determined that it contains transactions that do not originat.
Instance 'innodb-cluster01:3308' has the following errant GTIDs that do not exist in the cluster:
12d96b6c-8256-11f1-94a0-000c2951f167:1
WARNING: Discarding these extra GTID events can either be done manually or by completely overwriting the state of 'innodb-cluster01:3308.
Having extra GTID events is not expected, and it is recommended to investigate this further and ensure that the data can be removed prio.
Please select a recovery method [C]lone/[A]bort (default Abort): C
Validating instance configuration at localhost:3308...
This instance reports its own address as innodb-cluster01:3308
Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'innodb-cluster01:3308'. Use the localAddress option to override.
* Checking connectivity and SSL configuration...
A new instance will be added to the InnoDB Cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.
Adding instance to the cluster...
Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
Clone based state recovery is now in progress.
NOTE: A server restart is expected to happen as part of the clone process. If the
server does not support the RESTART command or does not come back after a
while, you may need to manually start it back.
* Waiting for clone to finish...
NOTE: innodb-cluster01:3308 is being cloned from innodb-cluster01:3306
** Stage DROP DATA: Completed
** Clone Transfer
FILE COPY ############################################################ 100% Completed
PAGE COPY ############################################################ 100% Completed
REDO COPY ############################################################ 100% Completed
* Clone process has finished: 77.08 MB transferred in about 1 second (~77.08 MB/s)
State recovery already finished for 'innodb-cluster01:3308'
The instance 'innodb-cluster01:3308' was successfully added to the cluster.
MySQL 127.0.0.1:3306 ssl JS >
-- 查看集群状态
MySQL 127.0.0.1:3306 ssl JS > cluster.rescan();
Rescanning the cluster...
Result of the rescanning operation for the 'myCluster' cluster:
{
"metadataConsistent": true,
"name": "myCluster",
"newTopologyMode": null,
"newlyDiscoveredInstances": [],
"unavailableInstances": [],
"updatedInstances": []
}
MySQL 127.0.0.1:3306 ssl JS > cluster.status()
{
"clusterName": "myCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "innodb-cluster01:3306",
"ssl": "REQUIRED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"innodb-cluster01:3306": {
"address": "innodb-cluster01:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.4.10"
},
"innodb-cluster01:3307": {
"address": "innodb-cluster01:3307",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.4.10"
},
"innodb-cluster01:3308": {
"address": "innodb-cluster01:3308",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.4.10"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "innodb-cluster01:3306"
}
MySQL 127.0.0.1:3306 ssl JS >
-- 配置mysqlrouter
mysqlrouter --bootstrap root@localhost:3306 --directory /mysql01/mysqlrouter --user=root
[root@innodb-cluster01 ~]# mysqlrouter --bootstrap root@localhost:3306 --directory /mysql01/mysqlrouter --user=root
Please enter MySQL password for root:
# Bootstrapping MySQL Router 9.7.1 (MySQL Community - GPL) instance at '/mysql01/mysqlrouter'...
- Creating account(s) (only those that are needed, if any)
- Verifying account (using it to run SQL queries that would be run by Router)
- Storing account in keyring
- Adjusting permissions of generated files
- Creating configuration /mysql01/mysqlrouter/mysqlrouter.conf
# MySQL Router configured for the InnoDB Cluster 'myCluster'
After this, MySQL Router can be started with the generated configuration with:
$ mysqlrouter -c /mysql01/mysqlrouter/mysqlrouter.conf
InnoDB Cluster 'myCluster' can be reached by connecting to:
## MySQL Classic protocol
- Read/Write Connections: localhost:6446
- Read/Only Connections: localhost:6447
- Read/Write Split Connections: localhost:6450
## MySQL X protocol
- Read/Write Connections: localhost:6448
- Read/Only Connections: localhost:6449
[root@innodb-cluster01 ~]#
-- 启动mysqlrouter ,使用mysqlrout目录下自动生成的脚本启动
--查看到的用户,看到多了mysql_innodb_cluster_1、mysql_innodb_cluster_2、mysql_innodb_cluster_3. 格式是mysql_innodb_cluster+ server id
root@db:3306 14:30:09 [(none)]> select host,user from mysql.user;
+-----------+------------------------+
| host | user |
+-----------+------------------------+
| % | icadmin |
| % | mysql_innodb_cluster_1 |
| % | mysql_innodb_cluster_2 |
| % | mysql_innodb_cluster_3 |
| % | mysql_router1_s61560t |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------------+
9 rows in set (0.00 sec)
root@db:3306 14:30:17 [(none)]>
-- 查看mgr状态,3306是primary
select * from performance_schema.replication_group_members;
root@db:3306 14:27:15 [(none)]>
root@db:3306 14:27:15 [(none)]> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+------------------+-------------+--------------+-------------+------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBE|
+---------------------------+--------------------------------------+------------------+-------------+--------------+-------------+------+
| group_replication_applier | 12d96b6c-8256-11f1-94a0-000c2951f167 | innodb-cluster01 | 3308 | ONLINE | SECONDARY | 8.4.1|
| group_replication_applier | 7c52d66e-8251-11f1-a139-000c2951f167 | innodb-cluster01 | 3306 | ONLINE | PRIMARY | 8.4.1|
| group_replication_applier | c57f918e-8253-11f1-8af0-000c2951f167 | innodb-cluster01 | 3307 | ONLINE | SECONDARY | 8.4.1|
+---------------------------+--------------------------------------+------------------+-------------+--------------+-------------+------+
3 rows in set (0.00 sec)
root@db:3306 14:28:19 [(none)]>
--根据mysqlrouter中的配置文件,6446端口是读写的
[root@innodb-cluster01 mysql330601]# mysql -uroot -h127.0.0.1 -p -P6446
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'innodb-cluster01' (using password: YES)
[root@innodb-cluster01 mysql330601]# mysql -uicadmin -h127.0.0.1 -p -P6446
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 0
Server version: 9.7.1-router MySQL Community Server - GPL
Copyright (c) 2000, 2026, 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 '\h' for help. Type '\c' to clear the current input statement.
icadmin@db:6446 14:32:21 [(none)]> select @@port;
+--------+
| @@port |
+--------+
| 3306 |
+--------+
1 row in set (0.00 sec)
icadmin@db:6446 14:32:29 [(none)]>
--根据mysqlrouter中的配置文件,6447端口是只读的,并且在3307和3308之间轮询
icadmin@db:6446 14:32:29 [(none)]> \q
Bye
[root@innodb-cluster01 mysql330601]# mysql -uicadmin -h127.0.0.1 -p -P6447
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 0
Server version: 9.7.1-router MySQL Community Server - GPL
Copyright (c) 2000, 2026, 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 '\h' for help. Type '\c' to clear the current input statement.
icadmin@db:6447 14:33:15 [(none)]> select @@port;
+--------+
| @@port |
+--------+
| 3307 |
+--------+
1 row in set (0.00 sec)
icadmin@db:6447 14:33:25 [(none)]> \q
Bye
[root@innodb-cluster01 mysql330601]# mysql -uicadmin -h127.0.0.1 -p -P6447
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 0
Server version: 9.7.1-router MySQL Community Server - GPL
Copyright (c) 2000, 2026, 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 '\h' for help. Type '\c' to clear the current input statement.
icadmin@db:6447 14:33:32 [(none)]> select @@port;
+--------+
| @@port |
+--------+
| 3308 |
+--------+
1 row in set (0.00 sec)
icadmin@db:6447 14:33:34 [(none)]>
END