0

I have a little problem, I can't seem to connect to mysql server community edition running inside a docker container.

I can easily connect to mysql server using the cli by using:

docker exec -it mysqlserver mysql -uroot -p

But if I try to connect with any other database connector, like DataGrip or MySql Workbench, I get an access denied.

But I changed nothing in the configuration files. I set ip as localhost, using the default 3306 port that the container exposed. username I keep as root and the password is exactly the same but it still keeps failing.

Am I missing something, not understanding anything properly?

Some help would be greatly appreciated!

Extra info: I am using MacOS, running the container with Docker for Mac and I am using as of this moment the latest MySql database version.

3
  • 1
    docker-compose.yml? Commented Jan 11, 2018 at 19:46
  • I am not using a docker-conpose.yml or should i be using one? I am new to docker, trying to understand it. Commented Jan 11, 2018 at 21:06
  • I asked because you give absolutely no info on how you run it and what your settings are. Commented Jan 12, 2018 at 12:09

2 Answers 2

1

your container doesn't contain other connectors, try to publish port when you run your container with docker run --name mysql -p 127.0.0.1:3306:3306 .... to link port. And you can connect you to the container with your local cli. Try this doc

Sign up to request clarification or add additional context in comments.

2 Comments

I tried it but I keep getting the samen errors, only way i am able to connect to mysql server running in the contrainer is trough docker itself using: docker exec -it mysql mysql -uroot -p using an 'external' method keeps leading to an acces denied, I really feel like I missing a key piece of information that I have to know about how the containers work.
Worked for me, with docker run -p 127.0.0.1:3306:3306 --name test -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest Check logs and wait for mysql starts completly, you can connect inside container to verify. And after from your host mysql -h 127.0.0.1 -u root -p
1

Below is the docker-compose.yml that I used to start up a MariaDB instance for testing some queries. MariaDB is API-compatible with MySQL, so no difference.

version: "2"

services:
  db:
    image: bitnami/mariadb:latest
    volumes:
      - ./mariadb/data:/bitnami
    ports:
      - "9001:3306"
    environment:
      MARIADB_ROOT_PASSWORD: ChangeMeIfYouWant
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    ports:
      - "9010:80"
    links:
      - db:db

The image is downloaded and the container created and started via docker-compose up. Afterwards, I can easily connect to it using JetBrains DataGrip.

host: localhost
port: 9001
user: root
password: ChangeMeIfYouWant

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.