Bug 22128: Use DROP USER IF EXISTS instead of GRANT USAGE before DROP USAGE

MySQL 5.7 is old, and the latest versions fail on "GRANT USAGE" if the
user does not exist. "DROP USER IF EXISTS" has been with us since 5.7,
so all users should have it by now. This patch fixes the issue.

To test:

Try to koha_remove a site, and if it works with no errors, all good!

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Rudolf Byker 2019-05-24 13:25:45 -05:00 committed by Martin Renvoize
parent 4dcf416dc9
commit e9bb407f62
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 2 additions and 4 deletions

View File

@ -67,10 +67,8 @@ do
then
# The grant creates the user in case it isn't, we don't want our loop to fail if it has already being deleted.
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`%\`;
GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`$mysql_hostname\`;
DROP USER \`koha_$name\`@\`%\`;
DROP USER \`koha_$name\`@\`$mysql_hostname\`;
DROP USER IF EXISTS \`koha_$name\`@\`%\`;
DROP USER IF EXISTS \`koha_$name\`@\`$mysql_hostname\`;
DROP DATABASE IF EXISTS \`koha_$name\`;
FLUSH PRIVILEGES;
eof