Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able to connect to mysql docker from local

Tags:

docker

mysql

I am trying to connect to mysql database from docker image. However it's throwing errors.

following is the docker image I am using. https://hub.docker.com/_/mysql/

And following is the command I have used to run the docker image.

docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=password -d mysql:8 

Following is the output of docker ps command

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                              NAMES 9f35d2e39476        mysql:8             "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp 

if I check the IP using docker inspect and ping that IP, it shows IP is not reachable.

docker inspect 9f35d2e39476 | grep -i ipaddress 

And if i try to connect using localhost and 127.0.0.1 I am getting following error.

Unable to load authentication plugin 'caching_sha2_password'.

like image 636
Gaurang Shah Avatar asked Feb 27 '18 23:02

Gaurang Shah


People also ask

How do I connect to a MySQL Docker database?

Here are the steps you can follow to install the Dockerhub MySQL Container: Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.

Can't connect to local MySQL server through?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

How can Docker container connect to localhost?

Use --network="host" in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.


1 Answers

First of all, be aware that you're using non stable software, so there can be major changes between releases and unexpected behaviour.

Edit: Is not in development anymore, stable release launched April 19, 2018

Secondly, you cannot ping directly your container, it's in other net, but you can easily use another container to ping him.

mysql 8 uses caching_sha2_password as the default authentication plugin instead of mysql_native_password. More info here.

Many mysql drivers haven't added support for caching_sha2_password yet.

If you're having problems with it, you can change to the old authentication plugin with something like this:

docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=password -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password

like image 72
Ivan Beldad Avatar answered Sep 18 '22 06:09

Ivan Beldad