Ability to add a new database with privileges for an existing user
This commit is contained in:
@@ -58,15 +58,16 @@ step_10() {
|
||||
read -p "Enter mysql user name: " mysqlUser
|
||||
endCheckEmpty mysqlUser "user name"
|
||||
|
||||
read -s -p "Enter mysql user password: " mysqlPass
|
||||
endCheckEmpty mysqlPass "password"
|
||||
exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';'
|
||||
saveReturn $?
|
||||
endReturn
|
||||
if ! echo "SELECT COUNT(*) FROM mysql.user WHERE user = '$mysqlUser';" | mysql | grep 1 &>/dev/null; then
|
||||
# User does not exist
|
||||
read -s -p "Enter mysql user password: " mysqlPass
|
||||
endCheckEmpty mysqlPass "password"
|
||||
exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';'
|
||||
endReturn -o $? "Error creating mysql user"
|
||||
fi
|
||||
|
||||
exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';'
|
||||
saveReturn $?
|
||||
endReturn
|
||||
endReturn -o $? "Error assigning privileges on database"
|
||||
|
||||
exe mysql -u root -e 'FLUSH PRIVILEGES;'
|
||||
}
|
||||
@@ -92,15 +93,16 @@ step_12() {
|
||||
read -p "Enter mysql user name: " mysqlUser
|
||||
endCheckEmpty mysqlUser "user name"
|
||||
|
||||
read -s -p "Enter mysql user password: " mysqlPass
|
||||
endCheckEmpty mysqlPass "password"
|
||||
exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';'
|
||||
saveReturn $?
|
||||
endReturn
|
||||
if ! echo "SELECT COUNT(*) FROM mysql.user WHERE user = '$mysqlUser';" | mysql | grep 1 &>/dev/null; then
|
||||
# User does not exist
|
||||
read -s -p "Enter mysql user password: " mysqlPass
|
||||
endCheckEmpty mysqlPass "password"
|
||||
exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';'
|
||||
endReturn -o $? "Error creating mysql user"
|
||||
fi
|
||||
|
||||
exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';'
|
||||
saveReturn $?
|
||||
endReturn
|
||||
endReturn -o $? "Error assigning privileges on database"
|
||||
|
||||
exe mysql -u root -e 'FLUSH PRIVILEGES;'
|
||||
}
|
||||
|
Reference in New Issue
Block a user