Can I use MySQL “stored procedures”?

Advanced users can use MySQL stored procedures. Here’s an example of creating one:

mysql> DELIMITER //
mysql> CREATE PROCEDURE TestProcedure(IN param TEXT)
   -> BEGIN
   ->   SELECT(SUBSTRING(param, 2));
   -> END //
Query OK, 0 rows affected (0.00 sec)

Then you can disconect and reconnect, and see that the procedure is usable:

mysql> CALL TestProcedure('tigertech');
+-----------------------+
| (SUBSTRING(param, 2)) |
+-----------------------+
| igertech              |
+-----------------------+
1 row in set (0.00 sec)

Why do I get an “access denied” error when creating a stored procedure?

This is almost always caused by including a “DEFINER” in the “CREATE PROCEDURE” command, where the definer refers to an invalid user.

To avoid this problem, simply omit the “DEFINER” part. This will make the procedure be owned by the same user that created it, which is almost certainly what you want.