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 5.7 already includes DROP USER IF EXISTS, but for older versions I use pt-show-grants --drop from percona-toolkit and feed back the DROP USER part to mysql:
pt-show-grants --drop --only=$username | grep '^DROP USER' | mysql -v
If there are multiple username-hostname pairs this removes all of them.