MySQL in docker-compose — access denied

岁酱吖の 提交于 2019-12-12 19:35:13

问题


I try to start MySQL server with docker-compose. Here is docker-compose.yaml part:

  mysql:
    restart: always
    image: mysql:latest
    ports:
    - "3306:3306"
    volumes:
    - /Users/user/Documents/.docker/mysql/config:/etc/mysql/
    - /Users/user/Documents/.docker/mysql/data:/var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD='123'
    - MYSQL_ROOT_HOST='172.18.0.1'

You see I've specified root password and host as it is said here. Then I try to connect to db (using Intellij Idea if that matters):

jdbc:mysql://localhost:3306/?user=root&password=123&ssl=false

But it doesn't accept the credentials and writes to log:

Access denied for user 'root'@'172.18.0.1' (using password: YES)

Please advise on how to fix it. Thanks.


回答1:


Most likely you have initialized the mysql data directory when these were different:

environment:
- MYSQL_ROOT_PASSWORD='123'
- MYSQL_ROOT_HOST='172.18.0.1'

MySQL image only honors those vars when start a /var/lib/mysql directory from scratch.

So if you don't care about the data, empty your volume: /Users/user/Documents/.docker/mysql/data, or change the credentials manually from mysql terminal.



来源:https://stackoverflow.com/questions/44590775/mysql-in-docker-compose-access-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!