Checking if mysql user exists

前端 未结 7 1551
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 09:20

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

7条回答
  •  借酒劲吻你
    2021-02-02 09:50

    If you're deleting the MySQL user anyways, then there's really no need to check if it exists first. MySQL won't throw any errors if there's nothing to delete:

    DELETE FROM mysql.user WHERE User = 'username';
    

提交回复
热议问题