1

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...

Panagiss
  • 3,154
  • 2
  • 20
  • 34

1 Answers1

0

Try mysql -h 127.0.0.1 -P 3306 -u user -p

From the doc

Client programs determine what type of connection to make as follows:

If the host is not specified or is localhost, a connection to the local host occurs:

On Windows, the client connects using shared memory, if the server 
was started with the shared_memory system variable enabled 
to support shared-memory connections.

On Unix, MySQL programs treat the host name localhost specially, 
in a way that is likely different from what you expect compared to other 
network-based programs: the client connects using a Unix socket file. 
The --socket option or the MYSQL_UNIX_PORT environment 
variable may be used to specify the socket name.
Andrei Kovrov
  • 2,087
  • 1
  • 18
  • 28
  • thanks it worked. Something strange is happening with sockets and tcp/ip if you don't specify the -h and -P – Panagiss Dec 04 '20 at 01:20
  • i get this error now even though yesterday worked: 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 – Panagiss Dec 04 '20 at 17:29
  • It’s not related to the docker. Please create a separate question if you want to get answer. Moreover, now you’re using mariadb instead of mysql according your error. – Andrei Kovrov Dec 04 '20 at 18:18
  • yeah but that is strange. take in mind that i get this error executing mysql client... i will leave few hours and then i will create a new one with the second question and of course i will accept your answer. – Panagiss Dec 04 '20 at 18:24