summaryrefslogtreecommitdiff
path: root/sql/create_db.sh
blob: 5bf54af01fee05143af04acfa16dd3ad14de05f7 (plain)
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
58
59
60
61
62
63
64
65
66
#!/bin/sh

drop="y"
echo "Drop existing database and user? (y/n) [$drop]"
read x

if [ "$x" ] ; then
    drop=$x
fi

dbname="passman"
echo "Name of database to create [$dbname]:"
read x

if [ "$x" ] ; then
    dbname=$x
fi

uname="passman"
echo "Name of database user to create [$uname]:"
read x

if [ "$x" ] ; then
    uname=$x
fi

pword="PassMan123!"
echo "Password of database user [$pword]:"
read x

if [ "$x" ] ; then
    pword=$x
fi

script=/tmp/$$
rm -f $script
touch $script

if [ "$drop" = "y" ] ; then
    cat >> $script << END_OF_DROP
drop database if exists $dbname;
drop user if exists '$uname'@'localhost';
END_OF_DROP
fi

cat >> $script << END_OF_SQL

create database $dbname;
use $dbname;
grant all on *.* to '$uname'@'localhost' identified by '$pword';

create table pm_store
(
    id int not null auto_increment,
    description varchar(1024) not null,
    username varchar(256) not null,
    password varchar(256) not null,
    primary key (id)
);

END_OF_SQL

cat -n $script
mysql -u root -p < $script

rm -f $script