Docker Community Forums

Share and learn in the Docker community.

How to fix that mysql deny in docker container by interaction

(Lygoods) #1

How to fix that mysql deny in docker container by interaction
command line below.

docker exec -it mysql bash
root@0e8219f886bc:/# mysql -u root -p
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

(Sam) #2

this is normal mysql configuration… first i would look at the doc for the image you are using
then look at the doc for mysql

(Nickperkinslondon) #3

That’s not helpful!..why doesn’t it work? How to make it work?

(Gary Forghetti) #4

How did you start the MySQL docker container?
Show us the docker container run command or docker-compose.yml file settings.
Need to see what docker image including tag you used along with the --ENV parameters.


🐳  gforghetti:[~] $ docker container run -it --detach --name mysql-server --env MYSQL_RANDOM_ROOT_PASSWORD=yes mysql:latest
🐳  gforghetti:[~] $ docker container logs mysql-server | grep 'GENERATED ROOT PASSWORD: ' | awk -F': ' '{print $2}'
🐳  gforghetti:[~] $ docker container exec -it mysql-server bash
root@0986bcaff934:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.14 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user,host from mysql.user;
| user             | host      |
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
5 rows in set (0.00 sec)

mysql> quit