Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

612
Visualizações
Can't connect to mysql container from localhost

I'm trying to set up a MySQL container for developing.

So I used docker-compose to set it up.

The container and the mysql looks OK. The thing is that I want to connect to it from a DBeaver client and I can't find how I do it.

Here is my docker-compose.yml:

version: '2'
services:
  db:
    image: 'mysql:5.7'
    volumes:
       - '~/dev/dbs-data/mysql:/var/lib/mysql'
    restart: 'always'
    expose: 
      - '3306'
    ports:
      - '3306:3306'
    environment:
       MYSQL_ROOT_PASSWORD: 'pass'
       MYSQL_DATABASE: 'db'
       MYSQL_USER: 'user'
       MYSQL_PASSWORD: 'pass'

When I try to connect it from DBeaver I get:

java.sql.SQLException: null,  message from server: 
"Host '172.18.0.1' is not allowed to connect to this MySQL server"

UPDATE

I'm not trying to connect using the IP 172.18.0.1. I tried to connect using localhost:3306, 127.0.0.1:3306 and with the sub IP docker gave it 0.0.0.0:3306

UPDATE

After having success connecting on my Mac, I tried again with DBeaver on my linux and again: enter image description here

Tried to connect with other tool, mysql workbench: enter image description here

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

As you can see in the official image documention :

MYSQL_ROOT_HOST : By default, MySQL creates the 'root'@'localhost' account. This account can only be connected to from inside the container, requiring the use of the docker exec command as noted under Connect to MySQL from the MySQL Command Line Client. To allow connections from other hosts, set this environment variable. As an example, the value "172.17.0.1", which is the default Docker gateway IP, will allow connections from the Docker host machine.

So you have to set the MYSQL_ROOT_HOST variable with the address 172.18.0.1 that you can see in the error message.

over 4 years ago · Santiago Trujillo Relatório

0

On Docker, run this command to create a MySql container and it will expose the ports to the outside world of docker.

docker run --name <mysql-container-name> -p 3306:3306 -e MYSQL_ROOT_PASSWORD=<root-password> -e MYSQL_USER=root -e MYSQL_PASSWORD=<user-password> -d mysql:latest

Few points to note: You may see below error when trying to connect with DBeaver:

Public Key Retrieval is not allowed

Solution: When creating a new connection on DBeaver, go to Driver Properties look for allowPublicKeyRetrievel and set it to TRUE. Also, if needed set useSSL to FALSE.

Test your connection from DBeaver or any other clients, and it should be working.

over 4 years ago · Santiago Trujillo Relatório

0

I am new to docker and was experiencing the same issue in Linux, it was an issue with the addresses allowed to accept connection; here is what worked out for me:

  1. Find the MySql configuration file named mysqld.cnf
    It would be: /etc/mysql/mysql.conf.d/mysqld.cnf
    Or if you have your own configuration file.
  2. Edit the bind-address key in it.
    Set it as:
    bind-address = 0.0.0.0
  3. This will allow to accept connections from any IP address
    Restart docker-compose by
    $ docker-compose down
    $ docker-compose up
  4. Wait for MySQL to start, it should work fine now.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda