4.1 连接MySQL Shell

使用 MySQL Shell 创建一个新容器来管理 MySQL InnoDB 集群。这是首选方法,尽管如果您需要对特定 pod 进行故障排除,每个 MySQL Operator for Kubernetes 和 MySQL InnoDB Cluster 容器也安装了 MySQL Shell。

这些示例假设 InnoDB Cluster 被命名为“mycluster”并使用“default”命名空间。

使用 MySQL Shell 创建新容器;此示例使用 MySQL Operator for Kubernetes 映像,但其他映像也适用,例如 mysql/mysql-server:8.0.

此示例使用“mysql/mysql-operator”映像创建一个名为“myshell”的新容器,并立即执行 MySQL Shell:

$> kubectl run --rm -it myshell --image=mysql/mysql-operator -- mysqlsh
If you don't see a command prompt, try pressing enter.

MySQL JS >

现在从 MySQL Shell 的界面连接到 InnoDB Cluster:

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)和 default命名空间。

可选择将其他参数传递给 mysqlsh,例如:

$> kubectl run --rm -it myshell --image=mysql/mysql-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 模式。

对特定容器进行故障排除

每个 MySQL Operator for Kubernetes 和 MySQL InnoDB Cluster 容器都安装了 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': ******

...