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