-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatedb.sh
More file actions
26 lines (21 loc) · 929 Bytes
/
Copy pathcreatedb.sh
File metadata and controls
26 lines (21 loc) · 929 Bytes
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
#!/usr/bin/env bash
# this only works if you have the mysqlclient installed. Keeping it around for an example.
# grab the username and password from the dotcloud environment.yml file
dbuser=`grep DOTCLOUD_DB_MYSQL_LOGIN ~/environment.yml | cut -f2 -d' '`
dbpass=`grep DOTCLOUD_DB_MYSQL_PASSWORD ~/environment.yml | cut -f2 -d' '`
# this is the database we want to create
dbname="trainingsdb"
#check if db exists
echo "Creating a database for $dbname"
DBS=`mysql -u$dbuser -p$dbpass -Bse 'show databases'| egrep -v 'information_schema|mysql'`
for db in $DBS; do
if [ "$db" = "$dbname" ] ; then
echo "This database already exists : exiting now"
exit
fi
done
#create database
mysqladmin -u$dbuser -p$dbpass create $dbname;
echo "Database $dbname created"
# if you wanted to, this is where you could create your user and give correct permissions
# and have the those values hard coded in your settings.py