Skip to content

Commit 03b5db6

Browse files
AirPettthelamer
authored andcommitted
Move the USE caluse to proper place and only add if default database was created.
1 parent e04963a commit 03b5db6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

root/etc/cont-init.d/40-initialise-db

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ else
5050
fi
5151

5252
# Make sure all user and database settings are set and pass is more than 4 characters
53+
# At the end change to default database created with environment variables to run init and remote scripts there
5354
if [ "${MYSQL_USER+x}" ] && \
5455
[ "${MYSQL_DATABASE+x}" ] && \
5556
[ "${MYSQL_PASSWORD+x}" ] && \
@@ -58,6 +59,7 @@ read -r -d '' MYSQL_DB_SETUP << EOM
5859
CREATE DATABASE \`${MYSQL_DATABASE}\`;
5960
CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
6061
GRANT ALL PRIVILEGES ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_USER}'@'%';
62+
USE \`${MYSQL_DATABASE}\`;
6163
EOM
6264
fi
6365

@@ -70,8 +72,6 @@ $MYSQL_DB_SETUP
7072
EONEWSQL
7173
echo "Setting Up Initial Databases"
7274

73-
echo "USE ${MYSQL_DATABASE};" >> "$tempSqlFile"
74-
7575
# add all sql from a user defined directory on first init
7676
if ([ -e "/config/initdb.d" ] && [ -n "$(/bin/ls -A /config/initdb.d/*.sql 2>/dev/null)" ]); then
7777
cat /config/initdb.d/*.sql >> "$tempSqlFile"

0 commit comments

Comments
 (0)