-
Notifications
You must be signed in to change notification settings - Fork 2
/
init-mysql.sh
executable file
·30 lines (25 loc) · 1.02 KB
/
init-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
#!/bin/bash
set -o errexit
# $0 <data-set-dir> [<mysql root password>]
[ ! -d $1 ] && (echo "usage: $0 <data-set-dir>"; exit 1)
echo "Creating gdbb database and user, using the following SQL:"
echo '----------------------------------------'
cat mysql/root.sql
echo '----------------------------------------'
if [ -z "$2" ]; then
echo "Please use mysql's root permissions."
mysql -uroot -p < mysql/root.sql
else
mysql -uroot -p"$2" < mysql/root.sql
fi
echo "Creating Procedures..."
mysql -ugdbb gdbb < mysql/init.sql
echo "Creating Tables..."
MYSQL_CMD="mysql --local-infile=1 -ugdbb gdbb"
# Drop all tables
mysqldump -ugdbb --add-drop-table --no-data gdbb | grep ^DROP | $MYSQL_CMD
# Create nodes and edges tables
echo "CALL create_graph_tables()" | $MYSQL_CMD
# Load csv files
echo "LOAD DATA LOCAL INFILE '${1}/nodes.csv' INTO TABLE nodes FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';" | $MYSQL_CMD
echo "LOAD DATA LOCAL INFILE '${1}/edges.csv' INTO TABLE edges FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';" | $MYSQL_CMD