模拟“如果不存在则创建用户”时出现语法错误

4

MySQL不允许在create user语句中指定if not exists子句(尽管create tablecreate procedure支持此功能)。2005年有一个关于此功能的请求,但MySQL开发人员没有采取任何措施,因此这可能不会很快实现:

http://bugs.mysql.com/bug.php?id=15287

我正在尝试使用以下语句模拟此功能:

if (select ifnull((select 1
                     from mysql.user
                    where User = 'recuser'
                      and Host = '%'), 0) = 0) then
  create user 'recuser'@'%' identified by password 'blah';
end if;

但MySQL抱怨if语句的语法有问题 - 我没有发现任何错误,希望其他人能指出问题所在。

谢谢!

2个回答

10

-2

MySQL仅支持存储过程内的流程控制结构。


1
它没有系统存储过程来添加/删除用户,也不能准备“创建用户”语句,因为不支持。这是喜欢MySQL的另一个原因吧。 - Ian Kemp
你告诉他一些他基本上已经知道的东西,而不是帮助他解决问题... - Cerin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接