let me start saying that I've Googled a lot in the past few days trying to solve this problem but I could not find anything doable that worked in my case to solve my probems.
I have a running container with MySQL:8.0.31. This is the content of my docker compose file.
mysqldb:
image: mysql:8.0.31
container_name: mysqlcontainer
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
volumes:
- ./dbinit/init.sql:/docker-entrypoint-initdb.d/0_init.sql
- $HOME/database:/var/lib/mysql
- ./mysqld.log:/var/log/mysqld.log
ports:
- 3307:3306
expose:
- 3306
environment:
MYSQL_DATABASE: usersdb
MYSQL_PASSWORD: Val12345-%
MYSQL_ROOT_PASSWORD: Val12345-%
SERVICE_TAGS: dev
SERVICE_NAME: mysqldb
networks:
- internalnet
I start my Docker container with the command
docker-compose up --build
When the docker is up and running I want to run a "init.sql" file containing the tables of my database for testing purposes. So I open another terminal and use this command from the root folder of my project:
docker exec -i mysqlcontainer mysql -uroot -pVal12345-% usersdb < ./dbinit/init.sql
But when I run this command I get:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
I've found other suggeted fixes in StackOverlfow. Here's the first post you get by google my problem, I've tried other solutions but nothing worked so far.
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) > This fixed did not work in my case because when I run the command:
shell> sudo grep 'temporary password' /var/log/mysqld.log
nothing shows up in the console.