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'.
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.
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.
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.
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
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