访问方式
目录
功能概述
Alauda Database for MySQL-MGR 提供多种方式访问 MySQL-MGR 集群,支持集群内外访问。本节介绍如何获取合适的连接地址,并使用 mysql
客户端工具在集群内外连接 MySQL-MGR 实例。
有关客户端库的详细连接示例,请参见 How to Access MySQL-MGR Instances
操作步骤
虚拟 IP
- 获取 Service 名称:根据实例名称,对应的 Service 名称为
${name}-read-write
和 ${name}-read-only
。
- 使用 MySQL 客户端连接。例如,访问读写服务:
mysql -h${instance_name}-read-write.${namespace} -P3306 -u${username} -p${password}
- 查看成员角色:
select * from performance_schema.replication_group_members;
主机端口
确认已部署的访问模式
确认字段配置为 NodePort。
kubectl -n ${namespace} get mysql ${name} -o jsonpath='{.spec.mgr.router.svcRW.type}'
- 获取 NodePort 访问端口:
kubectl get svc -n ${namespace} ${name}-read-write -o jsonpath='{.spec.ports[0].nodePort}'
- 使用 MySQL 客户端连接:
mysql -h${node_ip} -P${port} -u${username} -p${password}
- 查看成员角色:
select * from performance_schema.replication_group_members;