Mysql: MYSQL_ROOT_PASSWORD not working

Created on 7 Apr 2019  路  2Comments  路  Source: docker-library/mysql

I'm trying to create the following database using docker-compose:

version: '3.1'
services:
mysql:
    image: mysql:5.7.21
    restart: always
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./dbs/mysql:/var/lib/mysql

my .env:

MYSQL_ROOT_PASSWORD=password

but when I run: docker-compose up mysql

it prints:

mysql_1       | Initializing database
mysql_1       | 2019-04-06T23:10:49.591422Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1       | 2019-04-06T23:10:51.593155Z 0 [Warning] InnoDB: New log files created, LSN=45790
mysql_1       | 2019-04-06T23:10:52.027557Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
mysql_1       | 2019-04-06T23:10:52.190840Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 39210408-58c1-11e9-8d8b-0242ac180002.
mysql_1       | 2019-04-06T23:10:52.216439Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
mysql_1       | 2019-04-06T23:10:52.217204Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

my directory (ls -lah):

-rw-r--r--  1 brlebtag bruno 1,5K Abr  6 20:10 docker-compose.yml
-rw-r--r--  1 brlebtag bruno  111 Abr  6 19:58 .env

my docker version (docker --version):

Docker version 18.09.4, build d14af54

my docker-compose version (docker-compose --version):

docker-compose version 1.24.0, build 0aa59064

I don't know why...

question

Most helpful comment

The environment variable is passed properly and the container works as you'd expect

$ docker-compose up -d
Creating network "mysql-557_default" with the default driver
Creating mysql-557_mysql_1_b43993989be0 ... done

$ docker exec -it mysql-557_mysql_1_c15a8eaab158 bash

root@a2bee0dfac8e:/# env | grep -i password
MYSQL_ROOT_PASSWORD=password

root@a2bee0dfac8e:/# mysql -Uroot           
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

root@a2bee0dfac8e:/# mysql -Uroot -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)

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

All 2 comments

The environment variable is passed properly and the container works as you'd expect

$ docker-compose up -d
Creating network "mysql-557_default" with the default driver
Creating mysql-557_mysql_1_b43993989be0 ... done

$ docker exec -it mysql-557_mysql_1_c15a8eaab158 bash

root@a2bee0dfac8e:/# env | grep -i password
MYSQL_ROOT_PASSWORD=password

root@a2bee0dfac8e:/# mysql -Uroot           
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

root@a2bee0dfac8e:/# mysql -Uroot -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)

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

The warning you're seeing in the logs:

Initializing database
. . .
root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
. . .
Database initialized

Is from:
https://github.com/docker-library/mysql/blob/a7a737f1eb44db467c85c8229df9d886dd63460e/5.7/docker-entrypoint.sh#L108-L110

Gonna close since there isn't an issue with the image and your compose file works fine

Was this page helpful?
0 / 5 - 0 ratings