First of all, you need to check the host. The host can be ‘localhost’ or ‘%’. Check the existence of user accounts with host −
mysql> select user,host from MySQL.user;
This will produce the following output −
+------------------+-----------+ | 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)
Now, we are going to change the definer for user Bob and host is ‘%’. Following is the query to create a stored procedure with definer −
mysql> DELIMITER // mysql> CREATE DEFINER=`Bob`@`%` PROCEDURE `Message`() BEGIN select "Hello World"; END // Query OK, 0 rows affected (0.14 sec) mysql> DELIMITER ;
Now call the stored procedure with the help of CALL command −
mysql> call `Message`();
This will produce the following output −
+-------------+ | Hello World | +-------------+ | Hello World | +-------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)