MySQL: Check if the user exists and drop it

前端 未结 14 1759
遇见更好的自我
遇见更好的自我 2020-12-02 16:43

There’s not standard way to check if a MySQL user exists and based on that drop it. Are there any workarounds for this?

Edit: I need a straight way to run this wi

14条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 16:53

    This worked for me:

    GRANT USAGE ON *.* TO 'username'@'localhost';
    DROP USER 'username'@'localhost';
    

    This creates the user if it doesn't already exist (and grants it a harmless privilege), then deletes it either way. Found solution here: http://bugs.mysql.com/bug.php?id=19166

    Updates: @Hao recommends adding IDENTIFIED BY; @andreb (in comments) suggests disabling NO_AUTO_CREATE_USER.

提交回复
热议问题