Add IF EXISTS clause to DROP USER statement (#307) (#308)

* Add IF EXISTS clause to DROP USER statement

* Add a changelog fragment

* Fix exception

(cherry picked from commit 3a452faeb0)
This commit is contained in:
Andrew Klychkov 2022-03-15 17:30:23 +03:00 committed by GitHub
parent fecc9866e3
commit 66c340e951
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -419,7 +419,10 @@ def user_delete(cursor, user, host, host_all, check_mode):
hostnames = [host]
for hostname in hostnames:
cursor.execute("DROP USER %s@%s", (user, hostname))
try:
cursor.execute("DROP USER IF EXISTS %s@%s", (user, hostname))
except Exception:
cursor.execute("DROP USER %s@%s", (user, hostname))
return True