0

I have a docker setup that is running Mysql 8.

I am able to access Mysql inside docker container, however, I am unable to connect using Mysql workbench. I have another mysql container but this one is Mysql version 5.7 and I have no issues connecting with that one.

I have tried to allow root user full host access with % in the mysql.user

| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |

I have tried to connect to container using hostnames: localhost, 0.0.0.0, 127.0.0.1 and port 3306 but no luck

I also created a separate user and gave full privilege and still no luck

Below is my Docker compose file

version: '3.5'

services:
  database:
    build:
      context: ./images/mysql
    restart: always
    command: ['--default-authentication-plugin=mysql_native_password']
    environment:
      - MYSQL_DATABASE=inim
      - MYSQL_USER=inimuser
      - MYSQL_PASSWORD=inimpass
      - MYSQL_ROOT_PASSWORD=docker
    ports:
      - "3306:3306"
    volumes:
      - ./database/data:/var/lib

volumes:
  my-datavolume:

my Dockerfile:

FROM mysql:8.0.20

CMD ["mysqld"]

EXPOSE 3306

Below is my Docker PS

b8832d9711b4        docker_inim_db_database   "docker-entrypoint.s…"   14 minutes ago      Up 14 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp          docker_inim_db_database_1

I have a similar setup with Mysql 5.7 and it connects fine. Not sure what I am doing wrong here.

bodi87
  • 501
  • 1
  • 6
  • 18

1 Answers1

0

You can debug your process by going to the container. Please run:

$ docker exec docker_inim_db_database_1 /bin/bash

Now you should be in bash of the container. Then login to mysql bash using:

$ mysql -uroot -p

and type your password or just press Enter if none.

There's two steps in that process:

a) Grant privileges. As root user execute with this substituting 'password' with your current root password :

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

b) bind to all addresses:

The easiest way is to comment out the line in your my.cnf file:

#bind-address = 127.0.0.1 

and restart mysql

service mysql restart

By default it binds only to localhost, but if you comment the line it binds to all interfaces it finds. Commenting out the line is equivalent to bind-address=*.

To check where mysql service has binded execute as root:

netstat -tupan | grep mysql

Update For Ubuntu 16:

Config file is (now)

/etc/mysql/mysql.conf.d/mysqld.cnf 

Most of steps above are from answer: https://stackoverflow.com/a/11225588/659077

Mohsen Abasi
  • 2,050
  • 28
  • 30