forked from CenturyLinkLabs/docker-mysql
-
Notifications
You must be signed in to change notification settings - Fork 4
/
run
59 lines (48 loc) · 1.86 KB
/
run
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -e
rsyslogd
cron
SERVERID=${SERVERID:-""}
AI_INCREMENT=${AI_INCREMENT:-"1"}
AI_OFFSET=${AI_OFFSET:-"1"}
MYSQL_MAX_MEM=${MYSQL_MAX_MEM:-""}
if [[ $MYSQL_MAX_MEM != "" ]]; then
cat /etc/my-${MYSQL_MAX_MEM}.cnf > /etc/mysql/conf.d/my.cnf
fi
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user mysql > /dev/null
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-""}
MYSQL_DATABASE=${MYSQL_DATABASE:-""}
MYSQL_USER=${MYSQL_USER:-""}
MYSQL_PASSWORD=${MYSQL_PASSWORD:-""}
MYSQL_REPL_PASSWORD=${MYSQL_REPL_PASSWORD:-"replication"}
tfile=`mktemp`
if [[ ! -f "$tfile" ]]; then
return 1
fi
cat << EOF > $tfile
USE mysql;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
UPDATE user SET password=PASSWORD("$MYSQL_ROOT_PASSWORD") WHERE user='root';
EOF
if [[ $MYSQL_DATABASE != "" ]]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
if [[ $MYSQL_USER != "" ]]; then
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
fi
fi
if [[ $SERVERID != "" ]]; then
echo "log-bin = mysql-bin" >> /etc/mysql/conf.d/my.cnf
echo "server-id = ${SERVERID} " >> /etc/mysql/conf.d/my.cnf
echo "binlog-ignore-db = test" >> /etc/mysql/conf.d/my.cnf
echo "binlog-ignore-db = mysql " >> /etc/mysql/conf.d/my.cnf
echo "replicate-ignore-db = test " >> /etc/mysql/conf.d/my.cnf
echo "replicate-ignore-db = mysql " >> /etc/mysql/conf.d/my.cnf
echo "auto-increment-increment = ${AI_INCREMENT}" >> /etc/mysql/conf.d/my.cnf
echo "auto-increment-offset = ${AI_OFFSET}" >> /etc/mysql/conf.d/my.cnf
echo "grant replication client,replication slave on *.* to 'repl'@'%' identified by '$MYSQL_REPL_PASSWORD';" >> $tfile
fi
/usr/sbin/mysqld --bootstrap --verbose=0 < $tfile
rm -f $tfile
exec /usr/sbin/mysqld