-
Notifications
You must be signed in to change notification settings - Fork 2
/
mkdbrouser.sh
executable file
·70 lines (55 loc) · 983 Bytes
/
mkdbrouser.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
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
67
68
69
#!/bin/bash
#
# Usage: mkdbrouser.sh dbuser db
#
#
# the prep
#
DBUSER=$1
DB=$2
if [ $# -ne 2 ]
then
echo "Usage: mkdbrouser.sh dbuser db "
echo "Creates DB user \"dbuser\" with Read-Only privs on \"db\". "
exit
else
echo "User: $DBUSER "
fi
stty -echo
echo -n "Enter mysql passwd for ${DBUSER}: "
read PASSWORD
stty echo
echo ""
#
# the SQL
#
# disable pathname expansion on *'s in SQL statement
set -f
SQL_STATEMENT="\
CREATE USER '${DBUSER}'@'%'
IDENTIFIED BY '${PASSWORD}' ;
GRANT USAGE ON *.* TO '${DBUSER}'@'%'
IDENTIFIED BY '${PASSWORD}' WITH
MAX_QUERIES_PER_HOUR 0
MAX_CONNECTIONS_PER_HOUR 0
MAX_UPDATES_PER_HOUR 0
MAX_USER_CONNECTIONS 0 ;
GRANT SELECT, CREATE TEMPORARY TABLES, SHOW VIEW
ON \`${DB}\`.* TO '${DBUSER}'@'%' ;
"
#
# run it
#
echo "-----"
# username (root) and password are now stored in a file
echo $SQL_STATEMENT | mysql
MYSQLSTAT=$?
if [ $MYSQLSTAT -eq '0' ]
then
echo ""
echo "SUCCESS"
echo ""
fi
#
# End
#