forked from convox/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·36 lines (29 loc) · 1.29 KB
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
chown -R mysql "$MYSQL_DATA"
# TODO: Check if mysql already configured...
mysql_install_db --user=mysql
if [ ! -d "/run/mysqld" ]; then
mkdir -p /run/mysqld
fi
chown -R mysql "$MYSQL_RUN"
cat << EOF > $MYSQL_INITFILE
USE mysql;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
SET GLOBAL max_connect_errors=18446744073709551615;
EOF
if [ "$MYSQL_DATABASE" != "" ]; then
echo "[i] Creating database: $MYSQL_DATABASE"
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $MYSQL_INITFILE
if [ "$MYSQL_USERNAME" != "" ]; then
echo "[i] Creating user: $MYSQL_USERNAME with password $MYSQL_PASSWORD"
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USERNAME'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $MYSQL_INITFILE
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USERNAME'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $MYSQL_INITFILE
fi
fi
chown mysql "$MYSQL_INITFILE"
/usr/bin/mysqld_safe --user=root --init-file=$MYSQL_INITFILE
/usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | /usr/bin/mysql -u root mysql
rm -f $MYSQL_INITFILE
exec gosu mysql "$@"