From b8b7b0c3bf63413412befc531c044f2c94dac0fa Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 14 Nov 2018 13:19:47 +0100 Subject: [PATCH] Upload files to '' Added bash script --- sql_datauser.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 sql_datauser.sh diff --git a/sql_datauser.sh b/sql_datauser.sh new file mode 100644 index 0000000..32eb630 --- /dev/null +++ b/sql_datauser.sh @@ -0,0 +1,37 @@ +# 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