Checking if mysql user exists

前端 未结 7 1554
被撕碎了的回忆
被撕碎了的回忆 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 10:06

    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

    0 讨论(0)
提交回复
热议问题