How can I check if a user exists?
Im doing an installer for a mysql database, and I need to check if a user exits, if not create user, if yes delete user and create it a
MySQL lacks DROP USER IF EXISTS construct.
A good workaround is to grant a harmless privilege to the user before dropping it. This will create the user if it doesn't exist, so that it can be dropped safely, like so:
GRANT USAGE ON *.* TO 'username'@'localhost';
DROP USER 'username'@'localhost';
FLUSH PRIVILEGES;
USAGE actually means no privilege.
Source: http://bugs.mysql.com/bug.php?id=19166