- mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
-DROP USER \`koha_$name\`;
-DROP DATABASE \`koha_$name\`;
+ # 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 DATABASE IF EXISTS \`koha_$name\`;