Skip to content

Mysql root user is not initialized #216

Closed
@Kern046

Description

@Kern046

Hello there !

I am facing some kind of problem with the 5.7 image. The short description is that the container is set up properly, but it is impossible to connect with the root user. My suggestion is that the root password is not initialized properly.

I am using docker-toolbox with Windows (quite sad about it but due to VPN and company group strategies it is quite hard to setup a Unix environment here) and I think Windows permissions are the problem.

I copy here my files :

docker-compose.yml

mysql:
    container_name: my_mysql_container
    build: mysql
    environment:
        - MYSQL_DATABASES=my_database
        - MYSQL_ROOT_PASSWORD=root
        - MYSQL_HOST=127.0.0.1
        - MYSQL_PORT=33306
        - MYSQL_USER=helpless
        - MYSQL_PASSWORD=dev
        - MYSQL_LOYALTY_DATABASE=my_database
    ports:
        # MySQL
        - "33306:3306"
    volumes:
        # Mysql
        - "./volumes/mysql:/var/lib/mysql"

mysql/Dockerfile

FROM mysql:5.7
MAINTAINER Helpless Dev <helpless.dev@wonderful_company.com>

COPY conf.d/*.cnf /etc/mysql/conf.d/
COPY docker-entrypoint-initdb.d/databases.sh /docker-entrypoint-initdb.d/databases.sh
COPY docker-entrypoint-initdb.d/config.sh /docker-entrypoint-initdb.d/config.sh

RUN chmod a+x /docker-entrypoint-initdb.d/config.sh && chown root:root /docker-entrypoint-initdb.d/config.sh
RUN chmod a+x /docker-entrypoint-initdb.d/databases.sh && chown root:root /docker-entrypoint-initdb.d/databases.sh

mysql/conf.d/custom.cnf

[mysqld]
default-storage-engine=INNODB
init-connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
bind-address        = 0.0.0.0
skip-external-locking
key_buffer      = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
query_cache_limit   = 1M
query_cache_size        = 16M
expire_logs_days    = 10
max_binlog_size         = 100M

[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

[isamchk]
key_buffer      = 16M

docker-entrypoint-initdb.d/config.sh

#!/bin/bash

chmod 644 /etc/mysql/conf.d/custom.cnf

echo "ok"

exec "$@"

docker-entrypoint-initdb.d/databases.sh

#!/bin/bash

mysql=( mysql --protocol=socket -uroot )

if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
    mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
fi

IFS=',' read -a dbs <<< "$MYSQL_DATABASES"

if [ ${#dbs[@]} -gt 0 ];then
    for db in "${dbs[@]}"
    do
        if [ "$db" ]; then
            echo create database $db
            echo "CREATE DATABASE IF NOT EXISTS \`$db\` ;" | "${mysql[@]}"
        fi

    done

    if [ "${dbs[0]}" ]; then
        mysql+=( "${dbs[0]}" )
    fi
fi

if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
    if [ ${#dbs[@]} -gt 0 ]; then
        for db in "${dbs[@]}"
        do
            if [ "$db" ]; then
                echo "GRANT ALL ON \`"$db"\`.* TO '"$MYSQL_USER"'@'%' ;" | "${mysql[@]}"
            fi
        done
    fi

    echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
fi

I tried to change the permissions of custom.cnf because it is created in mode 666 and mysql ignores it with the message World writeable config file "custom.cnf" has been ignored. But my script is never executed, nor the databases.sh script which would fail anyway because the root user is not available.

I think the reason is that mysql cannot create the root user when failing at reading the config file, but when I removed the custom.cnf file, I had the following logs :

2016-09-26T11:40:30.936825Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-09-26T11:40:30.939713Z 0 [Note] mysqld (mysqld 5.7.15) starting as process 1 ...
2016-09-26T11:40:30.954868Z 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2016-09-26T11:40:30.956901Z 0 [Note] InnoDB: PUNCH HOLE support available
2016-09-26T11:40:30.959072Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-09-26T11:40:30.959141Z 0 [Note] InnoDB: Uses event mutexes
2016-09-26T11:40:30.959160Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-09-26T11:40:30.959348Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-09-26T11:40:30.959368Z 0 [Note] InnoDB: Using Linux native AIO
2016-09-26T11:40:30.959587Z 0 [Note] InnoDB: Number of pools: 1
2016-09-26T11:40:30.960271Z 0 [Note] InnoDB: Using CPU crc32 instructions
2016-09-26T11:40:30.966106Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-09-26T11:40:30.979996Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-09-26T11:40:30.981340Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2016-09-26T11:40:31.009740Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-09-26T11:40:31.081507Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-09-26T11:40:31.082573Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-09-26T11:40:31.188290Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2016-09-26T11:40:31.189949Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-09-26T11:40:31.190054Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-09-26T11:40:31.190480Z 0 [Note] InnoDB: Waiting for purge to start
2016-09-26T11:40:31.240774Z 0 [Note] InnoDB: 5.7.15 started; log sequence number 12135621
2016-09-26T11:40:31.241113Z 0 [Note] Plugin 'FEDERATED' is disabled.
2016-09-26T11:40:31.242288Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool



2016-09-26T11:40:31.248585Z 0 [Warning] World-writable config file './auto.cnf' is ignored.
2016-09-26T11:40:31.249364Z 0 [Warning] World-writable config file './auto.cnf' has been removed.





2016-09-26T11:40:31.249913Z 0 [Note] Salting uuid generator variables, current_pid: 1, server_start_time: 1474890030, bytes_sent: 0,
2016-09-26T11:40:31.250064Z 0 [Note] Generated uuid: '0775897e-83de-11e6-8440-0242ac110002', server_start_time: 281476451600687, bytes_sent: 68492832
2016-09-26T11:40:31.250115Z 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: 0775897e-83de-11e6-8440-0242ac110002.
2016-09-26T11:40:31.259733Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2016-09-26T11:40:31.260256Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2016-09-26T11:40:31.260418Z 0 [Note] IPv6 is available.
2016-09-26T11:40:31.260458Z 0 [Note]   - '::' resolves to '::';
2016-09-26T11:40:31.260500Z 0 [Note] Server socket created on IP: '::'.
2016-09-26T11:40:31.274069Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160926 11:40:31
2016-09-26T11:40:31.289454Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2016-09-26T11:40:31.289812Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2016-09-26T11:40:31.360977Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2016-09-26T11:40:31.487421Z 0 [Note] Event Scheduler: Loaded 0 events
2016-09-26T11:40:31.487685Z 0 [Note] mysqld: ready for connections.
Version: '5.7.15'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

I put in evidence the file permissions problems.

In the Dockerfile, I tried to run chmod 644, but after investigation, it is impossible with docker toolbox to modify the "o" permissions. I can do chmod u=rw,g=r but not u=rw,go=r or even a=r. I tried several combinations before concluding that it is impossible with docker toolbox on windows to change the "o" permissions during the building. I do not know if I have to do an issue in Docker Machine repository or Toolbox.

I would be glad if you can help me, that would avoid a Vagrant box on my Windows, which would be sad for me and my team :D !

Thanks a lot, and have a nice day !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions