-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-mysql-user.sh
More file actions
executable file
·28 lines (22 loc) · 875 Bytes
/
make-mysql-user.sh
File metadata and controls
executable file
·28 lines (22 loc) · 875 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
27
28
#!/bin/sh
# this just helps me remember the syntax...
# user=user
# password=password
# dbhost=localhost
: ${user:=$1}
: ${password:=$2}
: ${dbhost:=$3}
cat <<EOF
-- dbhost is where you access from -- can be localhost or % for any, or a specific hostname or ip (eg your webserver)
-- all privileges for $user@$dbhost (with password '$password')
CREATE USER '$user'@'$dbhost' IDENTIFIED BY '$password';
GRANT ALL PRIVILEGES ON *.* TO '$user'@'$dbhost' IDENTIFIED BY '$password'
WITH GRANT OPTION ;
-- database schema with same name?
create database \`$user\`;
-- sufficient for backups or export, no modifications
CREATE USER '$user'@'$dbhost' IDENTIFIED BY '$password'
GRANT SELECT , LOCK TABLES ON *.* TO '$user'@'$dbhost'
-- to limit, can also set these:
WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
EOF