MySQL 存储过程 DEFINER=`root`@`%` 在 localhost 中不起作用?
mysqlmysqli database
首先,您需要检查主机。主机可以是"localhost"或"%"。使用主机检查用户帐户是否存在−
mysql> select user,host from MySQL.user;
这将产生以下输出 −
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | David | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 17 rows in set (0.00 sec)
现在,我们将更改用户 Bob 的定义者,主机为 ‘%’。以下是使用定义者创建存储过程的查询 −
mysql> DELIMITER // mysql> CREATE DEFINER=`Bob`@`%` PROCEDURE `Message`() BEGIN select "Hello World"; END // Query OK, 0 rows affected (0.14 sec) mysql> DELIMITER ;
现在借助 CALL 命令调用存储过程 −
mysql> call `Message`();
这将产生以下输出 −
+-------------+ | Hello World | +-------------+ | Hello World | +-------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)