docker创建mysql实例连接不上,无法从Docker实例连接到MYSQL

I'm new to Docker and pulled the mysql from the docker hub using following command

docker pull mysql

Now, started mysql instance using following commands.

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql/mysql-server:latest

Unable to find image 'mysql/mysql-server:latest' locally

latest: Pulling from mysql/mysql-server

e64f6e679e1a: Pull complete

799d60100a25: Pull complete

85ce9d0534d0: Pull complete

d3565df0a804: Pull complete

Digest: sha256:59a5854dca16488305aee60c8dea4d88b68d816aee627de022b19d9bead48d04

Status: Downloaded newer image for mysql/mysql-server:latest

1be4f5dde2fb4e1d99e23ee2de5e3b663c7c2d0fabe7ef459cf87385071a2e0d

Now, I've checked what all services are up and running.

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

1be4f5dde2fb mysql/mysql-server:latest "/entrypoint.sh mysql" 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql

e7d9e3713f5c ubuntu "/bin/bash" 6 days ago Up 6 days angry_hodgkin

and now I execute the following commands and unable to connect to mysql -

mysql -h127.0.0.1 -ppassword -uroot

-bash: mysql: command not found

Docker version..

docker --version

Docker version 1.12.3, build 6b644ec

Now, I'm getting below erro - EDIT-1

docker exec -it 1be4f5dde2fb bash

bash-4.2# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

bash-4.2# sudo mysql

bash: sudo: command not found

解决方案

Get in the docker container using the following command

docker exec -it mysql bash

You can then easily connect to MySQL, by executing the following command

mysql -uroot -p

If you are trying to connect from the host machine, then you will have to install the mysql client.

On mac, the command is as follows

brew install mysql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值