代码之家  ›  专栏  ›  技术社区  ›  Ian Kemp

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

  •  4
  • Ian Kemp  · 技术社区  · 16 年前

    MySQL不允许您指定 if not exists a中的子句 create user 声明(尽管事实上 create table create 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 回复  |  直到 16 年前
        1
  •  10
  •   Community Mohan Dere    9 年前

    丹尼斯回答了你的精确问题,但围绕你的问题还有其他方法:看我对你的回答 mysql create user only when the user doesn't exist (也有类似存储过程的示例)

        2
  •  -2
  •   Denis Otkidach    16 年前

    MySQL只支持存储过程中的流控制结构。