-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmysql.sh
executable file
·28 lines (24 loc) · 933 Bytes
/
mysql.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
#!/bin/bash
set -u
sleep 4
database_connectivity_check=no
var=1
while [ "$database_connectivity_check" != "mysql" ]; do
/etc/init.d/mysql start
sleep 2
database_connectivity_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -o mysql`
if [ $var -ge 4 ]; then
exit 1
fi
var=$((var+1))
done
database_availability_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -ow "$MYSQL_DATABASE"`
if [ "$database_availability_check" == "$MYSQL_DATABASE" ]; then
exit 1
else
mysql -u root -p$MYSQL_ROOT_PASSWORD -e "grant all on *.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';"
mysql -u root -p$MYSQL_ROOT_PASSWORD -e "create database $MYSQL_DATABASE;"
mysql -u root -p$MYSQL_ROOT_PASSWORD -e "grant all on $MYSQL_DATABASE.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';"
supervisorctl stop database_creation && supervisorctl remove database_creation
echo "Database $MYSQL_DATABASE created"
fi