Tim Smeets
Tim Smeets

Reputation: 1

Connecting to MySql server running in a Docker Container

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.

Upvotes: 0

Views: 2796

Answers (2)

Grant Palin
Grant Palin

Reputation: 4558

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

Upvotes: 1

Kilian
Kilian

Reputation: 1781

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

Upvotes: 1

Related Questions