创建一个新的容器,其中包含用于管理 MySQL InnoDB 集群的 MySQL Shell。这是首选方法,但如果您需要对特定 Pod 进行故障排除,则每个 Kubernetes 版 MySQL Operator 和 MySQL InnoDB 集群容器也都安装了 MySQL Shell。
这些示例假设 InnoDB 集群名为“mycluster”并使用“默认”命名空间。
使用 MySQL Shell 创建新容器;此示例使用 Kubernetes 版 MySQL Operator 镜像,但其他镜像也可以使用,例如 container-registry.oracle.com/mysql/community-server:8.0
。
此示例使用 MySQL Operator 镜像创建一个名为“myshell”的新容器,并立即执行 MySQL Shell
$> kubectl run --rm -it myshell --image=container-registry.oracle.com/mysql/community-operator -- mysqlsh
If you don't see a command prompt, try pressing enter.
MySQL JS >
现在从 MySQL Shell 界面连接到 InnoDB 集群
MySQL JS> \connect root@mycluster
Creating a session to 'root@mycluster'
Please provide the password for 'root@mycluster': ******
MySQL mycluster JS>
root@mycluster
简写形式有效,因为它假定端口为 3306(MySQL 路由器重定向到 6446)并且命名空间为 默认
。
(可选)将其他参数传递给 mysqlsh,例如
$> kubectl run --rm -it myshell --image=container-registry.oracle.com/mysql/community-operator -- mysqlsh root@mycluster --sql
If you don't see a command prompt, try pressing enter.
******
MySQL mycluster SQL>
“******”表示在 MySQL Shell 默认提示输入密码时,输入 MySQL 用户的密码到 MySQL Shell。root@mycluster
表示主机 mycluster 上的用户 root,并假定命名空间为 默认。设置“-sql”将 MySQL Shell 初始化为 SQL 模式。
对特定容器进行故障排除
每个 Kubernetes 版 MySQL Operator 和 MySQL InnoDB 集群容器都安装了 MySQL Shell,因此,为了进行故障排除,您可能需要连接到集群中的特定 Pod。例如,连接到名为 mycluster-0 的 Pod
$> kubectl --namespace default exec -it mycluster-0 -- bash
Defaulted container "sidecar" out of: sidecar, mysql, initconf (init), initmysql (init)
bash-4.4#
bash-4.4# mysqlsh root@localhost
Please provide the password for 'root@localhost': ******
...