我写了一个批量修改用户权限的存储过程(因为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命令不支持变量吗
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命令不支持变量吗
mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+------------+
| hypotenuse |
+------------+
| 5 |
+------------+
mysql> DEALLOCATE PREPARE stmt1;