I'm running a Docker mysql container on my Mac laptop. Previously I was able to connect to it from the host OS with the mysql client. However, somehow it got deleted, and now after I re-created it, I can no longer to connect to it. I've searched dozens of similar questions, but am completely stumped.
Here's how I created it:
docker container run --name mysql-zhxw-dev -p 3306:3306 --expose=3306 -v zhxw-local-db-:/var/lib/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql:5.7.30
Every time I run mysql -u root -h 127.0.0.1
the following from my host OS, I get:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)
I can login to the container, and connect to mysql from within:
docker container exec -it mysql-zhxw-dev bash
mysql -u root <-- connects fine
I've tried:
- Omitting the named volume
- Specifying a password
- Various versions of mysql, including 5.6 and 5.7
- Logging in to the container with
docker container exec
, installingvi
, editing /etc/mysql/mysql.conf.d/mysqld.cnf and uncommenting the line that containsbind-address
. I tried it with bothbind-address = 0.0.0.0
andbind-address = 127.0.0.1
, then obviously exiting and runningdocker container restart mysql-zhxw-dev
. - Specifying port to connect to with
-P 3306
- Connecting with
-h localhost
,-h 127.0.0.1
,-h 0.0.0.0
, and omitting the-h
- Specifying
--protocol=TCP
when connecting
I'm at a loss as to what else to try.