I am trying to connect to mysql server using mysql cli. Image was created using following command:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d mysql
The docker container is running. docker ps
prints:
johnd@john-pc:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
598c0f8680dc mysql "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp some-mysql
When i enter the following command:
mysql -h 127.0.0.1 -P 3306 -u root -p
it returns:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
I also tried with --protocol=tcp
attribute. How do i connect from client to mysql server running on docker using terminal from client machine (not from another docker)
EDIT: I also tried connecting to mysql using this command:
docker run -it --rm mysql mysql -h127.0.0.1 -uexample-user -p
It returns the same error
mysql -h 127.0.0.1 -P 3306 -u root -p
You are connecting to your localhost's sql server but you didn't map the docker's container port to the host. Try mapping the port to your host by this:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d -p 3306:3306 mysql
Then retry:
mysql -h 127.0.0.1 -P 3306 -u root -p
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With