-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Comments
Similar issue #251 When I run the image without mounting the config file it runs as expected mysql/8.0/docker-entrypoint.sh Lines 177 to 193 in fc3e856
|
By default the container will have a
Whereas the The workaround is just use the env variables instead of putting those explicit env variable options in the options file. |
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 |
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 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' |
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 |
@ltangvald want to just roll this minor change into #471? |
This was resolved by #471. 👍 |
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):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:
However, if the line in the config file
database=test_database
is removed, the container/server start up as expectedThe text was updated successfully, but these errors were encountered: