How to fix that mysql deny in docker container by interaction

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

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

2 Likes

this is normal mysql configuration… first i would look at the doc for the image you are using
https://hub.docker.com/_/mysql/
then look at the doc for mysql

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

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.

Example.

🐳  gforghetti:[~] $ docker container run -it --detach --name mysql-server --env MYSQL_RANDOM_ROOT_PASSWORD=yes mysql:latest
0986bcaff9346b52acdb911e703e3e2b2b08a9d3ce3fecb5f2b1e35c2dc60283
🐳  gforghetti:[~] $ docker container logs mysql-server | grep 'GENERATED ROOT PASSWORD: ' | awk -F': ' '{print $2}'
wohy9inu5eiv3ash7oixoc7iizauph0V
🐳  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
owners.

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
Bye
root@0986bcaff934:/# 
1 Like

I’m having the same issue.

DockerFile

FROM mysql:5.7.24

LABEL MAINTAINER Myself <example@example.com>
LABEL description="Immagine DBMS MySql"


ADD dump.sql /docker-entrypoint-initdb.d

EXPOSE 3390

The dump.sql creates multiple databases with al the tables for each database. (Is it possible to do this?)

docker-compose.yml

version: '3.3'

networks: 
  ntalphash:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.20.0.0/24

services:
  mysql:
    build:
      context: .
    image: mysql:5.7.24
    restart: unless-stopped
    container_name: mysqlsrv
    volumes: 
      - data-volume:/var/lib/mysql
    networks: 
        ntalphash:
          ipv4_address: 172.20.0.2
    ports:
      - target: 3306
        published: 3390
        protocol: tcp
        mode: host
    environment:
      - MYSQL_ROOT_PASSWORD=admin

volumes:
  data-volume:

Here the commands i’m running on terminal:

Starting the container:

PS C:\Sql Server\MySql> docker-compose up                                                                                                                                                     Starting mysqlsrv ... done                                                                                                                                                                    Attaching to mysqlsrv
mysqlsrv | 2020-06-14T11:07:57.454914Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysqlsrv | 2020-06-14T11:07:57.455943Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
mysqlsrv | 2020-06-14T11:07:57.458112Z 0 [Note] InnoDB: PUNCH HOLE support available
mysqlsrv | 2020-06-14T11:07:57.458143Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysqlsrv | 2020-06-14T11:07:57.458148Z 0 [Note] InnoDB: Uses event mutexes
mysqlsrv | 2020-06-14T11:07:57.458151Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysqlsrv | 2020-06-14T11:07:57.458153Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysqlsrv | 2020-06-14T11:07:57.458155Z 0 [Note] InnoDB: Using Linux native AIO
mysqlsrv | 2020-06-14T11:07:57.458319Z 0 [Note] InnoDB: Number of pools: 1
mysqlsrv | 2020-06-14T11:07:57.458429Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysqlsrv | 2020-06-14T11:07:57.459511Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysqlsrv | 2020-06-14T11:07:57.465707Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysqlsrv | 2020-06-14T11:07:57.467263Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysqlsrv | 2020-06-14T11:07:57.478653Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysqlsrv | 2020-06-14T11:07:57.490450Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysqlsrv | 2020-06-14T11:07:57.490629Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysqlsrv | 2020-06-14T11:07:57.505991Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysqlsrv | 2020-06-14T11:07:57.506650Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysqlsrv | 2020-06-14T11:07:57.506677Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysqlsrv | 2020-06-14T11:07:57.507334Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 101589607
mysqlsrv | 2020-06-14T11:07:57.507516Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysqlsrv | 2020-06-14T11:07:57.507702Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqlsrv | 2020-06-14T11:07:57.509875Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200614 11:07:57
mysqlsrv | 2020-06-14T11:07:57.511163Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysqlsrv | 2020-06-14T11:07:57.511449Z 0 [Warning] CA certificate ca.pem is self signed.
mysqlsrv | 2020-06-14T11:07:57.513138Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysqlsrv | 2020-06-14T11:07:57.513304Z 0 [Note] IPv6 is available.
mysqlsrv | 2020-06-14T11:07:57.513313Z 0 [Note]   - '::' resolves to '::';
mysqlsrv | 2020-06-14T11:07:57.513327Z 0 [Note] Server socket created on IP: '::'.
mysqlsrv | 2020-06-14T11:07:57.515152Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysqlsrv | 2020-06-14T11:07:57.515869Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515907Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515915Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515920Z 0 [Warning] 'user' entry 'debian-sys-maint@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515937Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515939Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515946Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.516857Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.516888Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.521147Z 0 [Note] Event Scheduler: Loaded 0 events
mysqlsrv | 2020-06-14T11:07:57.521307Z 0 [Note] mysqld: ready for connections.
mysqlsrv | Version: '5.7.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

Checking for active containers:

C:\Users\Myself>docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS              PORTS                                         NAMES
ec9f9070939e        mysql:5.7.24                                        "docker-entrypoint.s…"   27 minutes ago      Up About a minute   3390/tcp, 33060/tcp, 0.0.0.0:3390->3306/tcp   mysqlsrv
64540c9d4bd1        portainer/portainer                                 "/portainer"             7 days ago          Up 46 minutes       0.0.0.0:9000->9000/tcp                        portainer
0345722e5fc3        mcr.microsoft.com/mssql/server:2017-latest-ubuntu   "/opt/mssql/bin/nonr…"   6 months ago        Up 46 minutes       0.0.0.0:1433->1433/tcp                        sqlserver

Then accessing the container and trying login mysql:

C:\Users\Myself>docker exec -ti mysqlsrv bash
root@ec9f9070939e:/# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
root@ec9f9070939e:/#

The password i’m typing is ‘admin’ as this is the password i’ve specified on the configuration file. I am a beginner with Docker. Anyone know what’s going on?

isn’t there a fix to this issue?

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Hello , so if you are creating an mysql/mysql-server image based container the documentation specifies that docker will generate a randomic root password.
So to check it out you can run the docker logs [my_sql_docker] (you put here de name or docker id from your container) and it will appear in the shell the random generated password for root

1 Like

I just wanted to thank you for this helpful response. I was able to set mysql thanks to you.

I was having the same problem.
I was runing a mysql container using : "sudo docker run --detach --name=MySqlTest --env=“MYSQL_ROOT_PASSWORD=123” --publish 6603:3306 --volume=/home/fabriciof/Documentos/Docker/MySqlContainer/conf.d:/etc/mysql/conf.d mysql
"

But after explicitly write the host ip: “sudo docker run --detach --name=MySqlTest --env=“MYSQL_ROOT_PASSWORD=123” --publish 127.0.0.1:6603:3306 --volume=/home/fabriciof/Documentos/Docker/MySqlContainer/conf.d:/etc/mysql/conf.d mysql”

I worked, i was able to connect using mysql client

I saw that video: How to run a MySQL server in a Docker container and connect to it from the host machine - YouTube