MySQL: Check if the user exists and drop it

前端 未结 14 1720
遇见更好的自我
遇见更好的自我 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:46

    To phyzome's answer (most highly voted one), it seems to me that if you put "identified by" at the end of the grant statement, the user will be created automatically. But if you don't, the user is not created. The following code works for me,

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

    Hope this helps.

提交回复
热议问题