模拟“创建用户(如果不存在)”的语法错误 [英] Syntax error with emulating "create user if not exists"
问题描述
MySQL不允许您在创建用户
语句中指定如果不存在
create table
和 create procedure
do支持这个)。 2005年有一个功能请求,但MySQL开发者已经完成了所有这一切,所以它可能不会发生任何时间很快:
http://bugs.mysql.com/bug.php?id=15287
我试图用下面的语句模拟这个功能:
if ifnull((从mysql.user
其中User ='recuser'
和Host ='%'选择1
,0)= 0)然后
创建用户'recuser' @'%'由密码'blah'标识;
end if;
但是MySQL抱怨在 if
语句 - 我看不到任何错误,希望有人可以指出问题是什么。
谢谢!
< div仅支持存储过程中的流控制结构。
MySQL does not allow you to specify an if not exists
clause in a create user
statement (despite the fact that create table
and create procedure
do support this). There was a feature request for this in 2005 but the MySQL devs have done sod all about it, so it's probably not going to happen anytime soon:
http://bugs.mysql.com/bug.php?id=15287
I'm trying to emulate this functionality with the following statement:
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;
but MySQL complains about the syntax in the if
statement - I can't see anything wrong with it, hopefully someone else can point out what the issue is.
Thanks!
MySQL supports flow control constructs within stored procedures only.
这篇关于模拟“创建用户(如果不存在)”的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!