-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-mysql.sh
49 lines (37 loc) · 1.31 KB
/
setup-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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -e
# database details
MYSQL_ROOT_PASSWORD=root_password
MYSQL_DATABASE1=cbioportal
MYSQL_DATABASE2=cgds_test
MYSQL_USER=cbio
MYSQL_PASSWORD=P@ssword1
# wait for database to start
echo "Waiting for MySQL to start..."
while ! mysqladmin ping -hlocalhost --silent; do
sleep 1
done
echo "MySQL started"
# check if the database has already been initialized
if [ -f /var/lib/mysql/.initialized ]; then
echo "Database already initialized."
exit 0
fi
echo "Initializing database, this will take a while..."
# initialize the database
mysql -u root <<-EOSQL
ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '${MYSQL_ROOT_PASSWORD}';
CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE1};
CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE2};
CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';
GRANT ALL ON ${MYSQL_DATABASE1}.* TO '${MYSQL_USER}'@'localhost';
GRANT ALL ON ${MYSQL_DATABASE2}.* TO '${MYSQL_USER}'@'localhost';
FLUSH PRIVILEGES;
EOSQL
# import the database schema
mysql --user=cbio --password=P@ssword1 cbioportal < /scripts/cgds.sql
# import the seed data
mysql --user=cbio --password=P@ssword1 cbioportal < /scripts/seed.sql
echo "Database initialized"
# mark the script as completed
touch /var/lib/mysql/.initialized