Bug 22128: Use DROP USER IF EXISTS instead of GRANT USAGE before DROP USAGE
authorRudolf Byker <rudolfbyker@gmail.com>
Fri, 24 May 2019 18:25:45 +0000 (13:25 -0500)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 28 Jun 2019 13:27:55 +0000 (14:27 +0100)
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>

debian/scripts/koha-remove

index 94f5915..ad31c8e 100755 (executable)
@@ -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