So i created a container of mysql like that
docker run --name mysqldb -v ~/Documents/docker/mysqldb:/var/lib/mysql -p 3306:3306 -e MYSQL_USER=user -e MYSQL_PASSWORD=pass123 -e MYSQL_DATABASE=students -e MYSQL_ROOT_PASSWORD=pass123 --rm -d mysql/mysql-server:latest
The thing is that when i try to connect with CLI i get Access denied. I run the command like that:
mysql -u user -p
Enter password:
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)
Then strange thing is that if i try to log in inside the container it's ok.
docker exec -it mysqldb bash
bash-4.2# mysql -u user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 99
Server version: 8.0.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
So i don't know what is going on...
UPDATE I followed Andrei Kovrov's answer and even tho it worked the last day, now i get this new error:
ERROR 1045 (28000): Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
UPDATE2 i managed to solve the above error-1045 problem following these steps:
I loged in the container
docker exec -it CONTAINER_ID bash then log into mysql as root
mysql --user=root --password Enter the password for root (Default is 'root') Finally Run:
ALTER USER 'username' IDENTIFIED WITH mysql_native_password BY 'password';
and the answer came from this github post. Ok it solved my problem but temporary cause whenever i drop the container and start it up again i face the same problem with that ERROR 1045 (28000): Plugin caching_sha2_password
. So it's a temporary solution but not final and correct...