Home > Back-end >  Unable to Connect to Localhost (MySQL Workbench on MariaDB Docker)
Unable to Connect to Localhost (MySQL Workbench on MariaDB Docker)

Time:08-27

I ran the following script:

docker run --detach --name mariadb-10.1.48 \
 --env MYSQL_USER=user --env MYSQL_PASSWORD='123' \
 --env MYSQL_ROOT_PASSWORD='abc' \
 -v /mnt/data/database/db_mysql:/var/lib/mysql \
 -v /mnt/data/database/db_mysql_config/my.cnf:/etc/mysql/my.cnf \
 mariadb:10.1.48

I already changed on my.cnf the following line "bind-address = 127.0.0.0" to:

bind-address=0.0.0.0

I can access locally via CLI. Using MySQL Workbench is giving me the error "Unable to connect to localhost"

PS: My enviroment is the following: Docker on Debian 11, i'm using Windows on the same network as the server trying to connect to the database using MySQL Workbench.

Please, what can i do? Thank you...

CodePudding user response:

You're running it in a container so you'd have to forward the ports or connect to the container IP.

docker inspect will get you the container IP if that's what you want.

Otherwise, change your docker command to the following to forward the port to your local machine:

docker run --detach --name mariadb-10.1.48 \
 --env MYSQL_USER=user --env MYSQL_PASSWORD='123' \
 --env MYSQL_ROOT_PASSWORD='abc' \
 -v /mnt/data/database/db_mysql:/var/lib/mysql \
 -v /mnt/data/database/db_mysql_config/my.cnf:/etc/mysql/my.cnf \
 -p 3306:3306 \
 mariadb:10.1.48

Note, if I'm understanding correctly your debian machine isn't WSL. So, from windows, 0.0.0.0 is the IP of the machine running docker. 0.0.0.0 is all the available IPs of localhost

  • Related