-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't connect with mysql-cli from host to mysql docker container #527
Comments
This isn't the image for this repo $ docker run --rm -dit -e MYSQL_ROOT_PASSWORD=pass --name mysql mysql:5.7
dbb50e8b064e160c9db788107c5d1caac478c7706074932ee843c68fbc98b1e9
$ docker logs mysql | tail -n 2
2018-12-17T20:28:31.848032Z 0 [Note] mysqld: ready for connections.
Version: '5.7.24' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
$ mysql -h172.17.0.2 -uroot -ppass
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I followed the post from @wglambert, tried to find out the IP-address with
|
Just figured it out, on Ubuntu it works. Not on Mac. On Mac even telnet fails:
Just found out, using docker image named with "mysql-5.7" works perfectly. |
I'm coming across the same issue @itinance was having. I have tried [same as @wglambert]:
But the if i try
i get
my mysql client
On the other hand if i go into the container, i can connect to this mysql instance, with no issues. Should i use a different mysql version?, client? server? Ideas? |
You'll want to wait for the second instance of With the refactored entrypoint #471 you can grep for $ docker run --rm -d -e MYSQL_ROOT_PASSWORD=pass --name mysql mysql:5.7
a40695221b16dcede76c80e792a9327a61d7bc569f359b7c88d76444c50034c7
$ docker inspect mysql | grep -i ipaddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
$ grep -i "ready for start up" <(docker logs mysql 2>&1)
2019-12-04 18:00:59+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
$ mysql -h172.17.0.2 -uroot -ppass
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> |
thanks @wglambert for your response. Still i get the same result: the response
takes like a minute to pop but it invariably does. |
Oh you're using Docker for Mac, that container is in a VM so expose the port https://docs.docker.com/docker-for-mac/networking/ |
@wglambert .. exposing the port:
if now i specify that port, i still get: Also tried specifying the protocol |
When you forward the port with |
that did not work either.. for some reason..
inside the box
tested it from inside the box and works... the back to the host machine:
|
Try connecting to the host |
It fails with |
thanks @wglambert, for your help. For some reason the host is supposed to be so this did work:
|
may u guys could try this, it works for me. docker exec -it mysql bash
mysql -h mysql-u yourmysqlusername -p
## change the host to blank
update mysql.user set host = ' ' where user = 'root';
flush privileges; |
Solution: ENV MYSQL_ROOT_HOST=% Please refer: Here's the relevant section: |
I had to add this to mysql service in docker-compose:
Then I could connect with |
If you do not want to use docker compose, you can use -p param for port binding
And do not use "localhost" but 127.0.0.1
|
I tried to connect mysql container in my python application on ubuntu,but I got this "Access denied for user 'root'@'172.17.0.1'",but Actually I just want to connect 172.17.0.2,That is my mysql container's IP.please help me |
Considering this,
change |
EDIT: this also assume you have no password set. Otherwise add that flag in. |
You can create second user without host prohibitions: By default root user created as 'root'@'localhost', so root user accepts only 127.0.0.1 IP. You connect to mysql docker from 172.17.0.2. |
That is incorrect for these images. The password for The default "host" is mysql/template/docker-entrypoint.sh Line 218 in 37981f6
This is where mysql/template/docker-entrypoint.sh Lines 266 to 273 in 37981f6
And here it also sets the password to the same for mysql/template/docker-entrypoint.sh Line 278 in 37981f6
|
hi ihave the same problem if i use --rm and then restart the pc after that my phpmyadmin cant find the container even i make new one so i remove the -rm . but if i make a network for mysql container it can be accesed with my phpmyadmin but cant connect with cli like this |
Hi,
I did the following to start a MySQL docker container:
I verified that its running with:
And also logged in to the conainer with:
What i could not achieve is connecting through the docker HOST mysql-cli to the docker container like this:
This did not work either:
This did also not work:
I found out the ip of the docker container over the docker bridge:
But using the IPAdress did also not work:
Am I too stupid to use docker or did I get something conceptually wrong or something else.
Thanks for enlightenment!
The text was updated successfully, but these errors were encountered: