Configure Mysql Workbench on Docker

Asked

Viewed 3,280 times

1

I want to set up my Workbench so that you can connect to the mysql that is running on my Docker server, but when I try to test the connection, I always get the following error: inserir a descrição da imagem aqui

I created my Mysql container using Docker-Compose. Below is the configuration of my Docker-Compose.yml:

php:
  build: .
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - ./teste:/var/www/html
  links: 
    - mysql  

mysql:
  image: mysql:latest
  volumes:
   - /var/lib/mysql
  environment:
   - MYSQL_ROOT_PASSWORD=123456
   - MYSQL_DATABASE=docker

phpmyadmin:
  image: phpmyadmin/phpmyadmin
  links:
   - mysql
  ports:
   - 3306:80
  environment:
   MYSQL_USERNAME: root
   MYSQL_ROOT_PASSWORD: 123456
   PMA_HOST: mysql

I am using windows 10 with version 13.07.1 of Docker. Both mysql Workbench and my server are running locally.

Currently for me to access my Docker project just type localhost in my browser, and to access phpmyadmin digit localhost:3306.

  • Provides a port in mysql tbm, and the port you provide vc puts in Workbench tbm. Dai sure it will work

2 answers

3


You need to map the mysql Docker port to the host. In your case it would look like this mysql snippet:

mysql:
  image: mysql:latest
  volumes:
   - /var/lib/mysql
  environment:
   - MYSQL_ROOT_PASSWORD=123456
   - MYSQL_DATABASE=docker
  ports:
   - 3306:3306
  • That’s right, just needed to map the mysql port. To work I also changed the port of phpmyadmin, to avoid conflict. Thank you.

-1

docker run --name mysqldb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql

Running the image in the shell, you need to set the port(-p 3306:3306) from your machine that will connect to the Mysql port on your Docker.

Example: 3306:3306, that is, when I access port 3306 of my machine I will be connecting with port 3306 of Mysql on my Docker.

This link shows the connection being made: https://imasters.com.br/data/utilizando-docker-com-mysql

  • 1

    Welcome and congratulations on the answer! But since the question indicates that Docker-Compose is used, use it in your answer. And also forget to format codes and avoid adding external references, as they can be changed or even removed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.