-
Notifications
You must be signed in to change notification settings - Fork 31
/
mysql_import
executable file
·57 lines (48 loc) · 1.43 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
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#
# This script will import the contents of the sql/ directory to the MySQL database.
#
# - Include common libraries and settings ------------------------------------
source "libui"
source "mysql_info"
# - Prepare required variables -----------------------------------------------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMP_FOLDER=${TMPDIR-/tmp}
# ----------------------------------------------------------------------------
# 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
for x in ./_extras/*_optimize.sql; do
import $x
done