38 lines
1014 B
Bash
38 lines
1014 B
Bash
![]() |
# sql_datauser.sh
|
||
|
# ---------------
|
||
|
#
|
||
|
# Very basic script to create a database on mysql whit its own user
|
||
|
# and password to be used by an application like a website,
|
||
|
# cloud, etc.
|
||
|
# As of the date below it has only been tested on mariaDB sql server.
|
||
|
#
|
||
|
# by Jony Silva
|
||
|
# Wed 14 Nov 11:53:12 GMT 2018
|
||
|
# Anti-copyright and/or BeerWare.
|
||
|
|
||
|
#!/usr/bin/env bash
|
||
|
message1="Creating database, user and password for new application."
|
||
|
message2="Give me DataBase user:"
|
||
|
message3="Give me DataBase user password:"
|
||
|
message4="Give me DataBase name:"
|
||
|
message5="Give me host(press enter for default\"localhost\"):"
|
||
|
|
||
|
echo $message1
|
||
|
echo $message4
|
||
|
read newDb
|
||
|
echo $message2
|
||
|
read newUser
|
||
|
echo $message3
|
||
|
read newDbPassword
|
||
|
echo $message5
|
||
|
read host
|
||
|
|
||
|
|
||
|
if [ -z "$host" ]
|
||
|
then host=localhost
|
||
|
fi
|
||
|
|
||
|
commands="CREATE DATABASE \`${newDb}\`;CREATE USER '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT ALL privileges ON \`${newDb}\`.* TO '${newUser}'@'${host}';FLUSH PRIVILEGES;"
|
||
|
|
||
|
echo "${commands}" | /usr/bin/mysql -u root -p
|