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.
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 the /var/lib/mysql directory is created.
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.