MySQL社区

标题: grant命令不能使用变量怎么办? [打印本页]

作者: ab19026    时间: 2013-5-14 18:46
标题: grant命令不能使用变量怎么办?
我写了一个批量修改用户权限的存储过程(因为mysql没有自定义用户组或者角色的机制),核心是这样的

declare username char(16);  //user表里的user就是char(16)类型的
begin
...
set username = '用户名';
grant insert on db.* to username@'localhost';
...
end

但总是提示ERROR 1133 (42000): Can't find any matching row in the user table
username = '用户名' 绝对是正确的,因为在存储过程里用 select user from mysql.user where user = username 是有结果的,但是用grant就不行,难道grant命令不支持变量吗
作者: kider    时间: 2013-5-15 11:46
要看清楚是否有这个用户,可以用show grants for username@'localhost'; 验证。

另外可以参考这个例子做:
http://www.mysqlpub.com/thread-34896-1-1.html
作者: ab19026    时间: 2013-5-15 19:27
kider 发表于 2013-5-15 11:46
要看清楚是否有这个用户,可以用show grants for username@'localhost'; 验证。

另外可以参考这个例子做 ...

动态有点麻烦,我还是修改mysql.db,然后flush privileges吧





欢迎光临 MySQL社区 (http://www.mysqlpub.com/) Powered by Discuz! X3.2