且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL:检查用户是否存在并删除它

更新时间:2023-11-28 18:42:58

这适用于我:

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

这会创建用户,如果它不存在(并授予它无害的权限)无论哪种方式。找到解决方案: http://bugs.mysql.com/bug.php?id=19166

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

更新: @Hao建议添加 IDENTIFIED BY ; @andreb(在评论中)建议禁用 NO_AUTO_CREATE_USER

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