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.
Here are the steps you can follow to install the Dockerhub MySQL Container: Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.
With Docker, you can run or scale your application in any environment. MySQL is one of the most popular SQL-compatible relational databases. Running MySQL inside a Docker container lets you separate your database from your code.
To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.
Remove all Containers: To remove all containers from the docker-machine, we need to get the ids of all the containers. We can simply get the ids of the containers with the command docker ps -aq, then by using the docker rm command, we can remove all the containers in the docker-machine.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With