-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmysql_import
executable file
·46 lines (39 loc) · 1.01 KB
/
mysql_import
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
#!/bin/bash
#
# This script will import the contents of the sql/ directory to the MySQL database.
#
. ./mysql_info
# Table prefix
PFX=
function import ()
{
db=$PFX`sed -ne '/^--.*Database: /{' -e 's/.*Database: //' -e 'p' -e '}' $1`
echo -n "Importing $1 into $db ..."
# Check if database exists
err=`echo "quit" | mysql$OPTS $db 2>&1`
if [ $? != 0 ]; then
if echo "$err" | grep -q "Access denied"; then
echo -e "\nDATABASE $db EXISTS BUT USER $USER DOES NOT HAVE ACCESS TO IT, ABORTING"
exit
fi
echo -n "[creating $db]"
if ! echo "CREATE DATABASE $db;" | mysql$OPTS 2>/dev/null ; then
echo -e "\nDATABASE $db DOES NOT EXIST AND I FAILED TO CREATE IT, ABORTING"
exit
fi
fi
mysql$OPTS $db <$1
echo " done"
}
for x in ./zp_characters/*.sql; do
import $x
done
for x in ./zp_realm/*.sql; do
import $x
done
for x in ./zp_scripts/*.sql; do
import $x
done
for x in ./zp_world/*.sql; do
import $x
done