如何打开mysql shell

时间:2018-02-13 17:41:07

标签: mysql ubuntu docker ubuntu-16.04

sudo docker run -i -t f92f0896ed95 /bin/bash

[Entrypoint] MySQL Docker Image 5.7.21-1.1.3
bash-4.2# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

bash-4.2# 

2 个答案:

答案 0 :(得分:0)

您必须使用凭据配置~/.my.cnf,然后可以直接打开mysql shell。

内容示例:

[client]
user=dba
password=foobar
# depends of what is configured, can be a hostname or 127.0.0.1, it's matter :
host=localhost

或者,如果您无法配置图像,请执行以下操作:

mysql -h localhost -p

然后系统会提示您输入密码

答案 1 :(得分:0)

首先运行图像标准,然后使用以下命令连接到正在运行的图像

docker exec -it f92f0896ed95 /bin/sh