3

How can I connect to MySQL inside my docker container that is hosted locally on my mac? I'm trying to connect via SequelPro and can't even get test connection to work.

Here's my Docker command:

docker run -it --name rodneys_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=demo mysql

I can connect via command line:

docker exec -it rodneys_mysql mysql -uroot -p

I know how to get the ip address of the docker container:

docker inspect <container id> | grep "IPAddress"

But I can't connect via SequelPro from my host machine.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rod
  • 14,529
  • 31
  • 118
  • 230
  • Possible duplicate of [Connect to Docker MySQL container from localhost?](https://stackoverflow.com/questions/32360687/connect-to-docker-mysql-container-from-localhost) – David Maze Sep 30 '18 at 17:30

3 Answers3

1

Solved by using 127.0.0.1 instead of localhost, because localhost would mean docker container itself. Also don't forget to grant user a privilege to connect:

grant all privileges on *.* to 'root'@'172.17.0.1' identified by 'password';

Or for all hosts:

grant all privileges on *.* to 'root'@'%' identified by 'password';
Alexander Kim
  • 17,304
  • 23
  • 100
  • 157
0

You are routing the local port 3306 of you machine to the container's port 3306. You should be able to use localhost in SequelPro.

mbuechmann
  • 5,413
  • 5
  • 27
  • 40
0

if you found this page and your docker-compose.yml misses the directly specified port, try to add the lines with ports in there like this:

mysql:
image: bitnami/mariadb:latest
ports:
  - "3306:3306"

that worked for me.

muinh
  • 535
  • 6
  • 14