Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server fails to start if "database" set in config file #448

Closed
CailanStm opened this issue Jul 8, 2018 · 8 comments
Closed

Server fails to start if "database" set in config file #448

CailanStm opened this issue Jul 8, 2018 · 8 comments
Labels

Comments

@CailanStm
Copy link

CailanStm commented Jul 8, 2018

When trying to run a mysql container with a default database, the container fails to start.

Using the following config, located in c:/path_to_config/custom.cnf on the host machine (Windows):

[mysqld]
skip-host-cache
skip-name-resolve

[client]
user=root
database=test_database

Run with the following command:
docker run --name test-mysql -v c:/path_to_config:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test_database mysql:latest

Produces the following output:

Initializing database
2018-07-08T19:04:58.324867Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-07-08T19:04:58.325053Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server in progress as process 27
mbind: Operation not permitted
mbind: Operation not permitted
2018-07-08T19:05:42.535112Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2018-07-08T19:05:52.786552Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.786612Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.786627Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.786772Z 5 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.786856Z 5 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.786871Z 5 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.787078Z 5 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.787442Z 5 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:05:52.787470Z 5 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:15.611042Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server has completed
Database initialized
MySQL init process in progress...
2018-07-08T19:06:20.224887Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-07-08T19:06:20.224997Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 78
mbind: Operation not permitted
mbind: Operation not permitted
MySQL init process in progress...
2018-07-08T19:06:21.879456Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-07-08T19:06:22.007040Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2018-07-08T19:06:22.017441Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.017520Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.017536Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.017548Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.017733Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.017778Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.017825Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.021208Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.021279Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-07-08T19:06:22.028424Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process in progress...
MySQL init process failed.

However, if the line in the config file database=test_database is removed, the container/server start up as expected

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Jul 9, 2018
@wglambert
Copy link

wglambert commented Jul 9, 2018

Similar issue #251

When I run the image without mounting the config file it runs as expected
Seems setting the database in the config conflicts with the env variable MYSQL_DATABASE

file_env 'MYSQL_DATABASE'
if [ "$MYSQL_DATABASE" ]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
mysql+=( "$MYSQL_DATABASE" )
fi
file_env 'MYSQL_USER'
file_env 'MYSQL_PASSWORD'
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}"
if [ "$MYSQL_DATABASE" ]; then
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}"
fi
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
fi

@wglambert
Copy link

By default the container will have a docker.cnf file in /etc/mysql/conf.d/ with contents of

[mysqld]
skip-host-cache
skip-name-resolve

Whereas the client options that you would otherwise include in the file are handled by the environment variables. However the canonical way of making a custom.cnffor that should otherwise be supported without environment variables, especially when they wouldn't otherwise be conflicting, and it isn't. So I'd consider that a possible issue.

The workaround is just use the env variables instead of putting those explicit env variable options in the options file.

@wglambert wglambert added Issue and removed question Usability question, not directly related to an error with the image labels Jul 11, 2018
@tianon
Copy link
Member

tianon commented Jul 16, 2018

I think what's happening here is that the entrypoint script is trying to connect to MySQL after initially starting it up so that it can do things like set up the initial user and create that initial database, but at that point the database doesn't exist yet (so the connection attempt probably fails due to the configuration now specifying that we need to use a specific database to connect). I think a solid workaround from our side would be to be explicit about the database we connect to initially, but it does make me wonder if there are other [client] options that are going to bite us in the same way later.

@tianon
Copy link
Member

tianon commented Jul 16, 2018

Here's an example of what might be sufficient changes to fix this one particular issue, but I'm still wary that there might be other issues and that we might be opening a can of worms here, so I think we need to look more at what's available to specify via [client] and see if anything else might cause similar types of issues.

diff --git a/8.0/docker-entrypoint.sh b/8.0/docker-entrypoint.sh
index 5ed7cd2..aa3350a 100755
--- a/8.0/docker-entrypoint.sh
+++ b/8.0/docker-entrypoint.sh
@@ -125,7 +125,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
 		mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
 
 		for i in {30..0}; do
-			if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
+			if echo 'SELECT 1' | "${mysql[@]}" mysql &> /dev/null; then
 				break
 			fi
 			echo 'MySQL init process in progress...'
@@ -158,7 +158,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
 			EOSQL
 		fi
 
-		"${mysql[@]}" <<-EOSQL
+		"${mysql[@]}" mysql <<-EOSQL
 			-- What's done in this file shouldn't be replicated
 			--  or products like mysql-fabric won't work
 			SET @@SESSION.SQL_LOG_BIN=0;
@@ -176,8 +176,10 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
 
 		file_env 'MYSQL_DATABASE'
 		if [ "$MYSQL_DATABASE" ]; then
-			echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
+			echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}" mysql
 			mysql+=( "$MYSQL_DATABASE" )
+		else
+			mysql+=( mysql )
 		fi
 
 		file_env 'MYSQL_USER'

@ltangvald
Copy link
Collaborator

It might be enough to just specify --database=mysql on the initial definition of the mysql variable (any command line options should override what's in the config file)?

@tianon
Copy link
Member

tianon commented Jul 30, 2018

It might be enough to just specify --database=mysql on the initial definition of the mysql variable (any command line options should override what's in the config file)?

Confirmed! The following does appear to do the trick:

diff --git a/8.0/docker-entrypoint.sh b/8.0/docker-entrypoint.sh
index 720ef6d..c778035 100755
--- a/8.0/docker-entrypoint.sh
+++ b/8.0/docker-entrypoint.sh
@@ -122,7 +122,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
 		"$@" --skip-networking --socket="${SOCKET}" &
 		pid="$!"
 
-		mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
+		mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" --database=mysql )
 
 		for i in {30..0}; do
 			if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then

@tianon
Copy link
Member

tianon commented Aug 24, 2018

@ltangvald want to just roll this minor change into #471?

@tianon
Copy link
Member

tianon commented Oct 10, 2019

This was resolved by #471. 👍

@tianon tianon closed this as completed Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants