Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to MySQL inside Docker container with SequelPro

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.

like image 440
Rod Avatar asked Dec 27 '25 22:12

Rod


1 Answers

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';
like image 182
Alexander Kim Avatar answered Dec 30 '25 16:12

Alexander Kim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!