How to connect mysql workbench to running mysql inside docker?
To configure your docker container with MySQL Workbench please follow the steps below.
-
In your docker-compose.yml you will have the following MySQL configuration block, if not add it. Here is an example of mine under the services object in my docker-compose.yml file.
services: db: image: mysql volumes: - "./.data/db:/var/lib/mysql" environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: mydatabase MYSQL_USER: user MYSQL_PASSWORD: secret ports: 33060:3306
-
Restart docker container with
docker-compose down
followed bydocker-compose up
and run following commands to get to the bash shell in the MySQL container. The name will appear under the name heading.docker ps docker exec -it <mysql container name> /bin/bash
Inside the container, to connect to mysql command line type,
mysql -u root -p
Use MYSQL_ROOT_PASSWORD as specified in the docker-compose.yml . Execute following commands to create new user. You are creating the user 'user' here. Change it to what you require but remeber to change it in docker and restart.
create user 'user'@'%' identified by 'pass'; grant all privileges on *.* to 'user'@'%' with grant option; flush privileges;
The percent sign (%) means all ip's. Restart the docker container.
-
In your MySQL Workbench provide the connection details. Use MYSQL_PASSWORD as specified in your docker-compose.yml file.
Categories: Posts