2 Ways to List all Stored Procedures in MySQL

Below are two options for returning a full list of stored procedures in MySQL.

The SHOW PROCEDURE STATUS Command

The quickest way to list out all stored procedures is to use the SHOW PROCEDURE STATUS command.

Simply run the following to list out all stored procedures:

SHOW PROCEDURE STATUS;

The syntax goes like this:

SHOW PROCEDURE STATUS
    [LIKE 'pattern' | WHERE expr]

So you can use a LIKE or WHERE clause to narrow the results down.

Example:

SHOW PROCEDURE STATUS LIKE 'albums%';

Result:

+-------+------------------------+-----------+----------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| Db    | Name                   | Type      | Definer        | Modified            | Created             | Security_type | Comment | character_set_client | collation_connection | Database Collation |
+-------+------------------------+-----------+----------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| Music | spAlbumsByGenre        | PROCEDURE | root@localhost | 2021-11-13 13:09:26 | 2021-11-13 13:09:26 | DEFINER       |         | utf8mb4              | utf8mb4_0900_ai_ci   | utf8mb4_0900_ai_ci |
| Music | spAlbumsFromArtistId   | PROCEDURE | root@localhost | 2021-11-13 13:03:25 | 2021-11-13 13:03:25 | DEFINER       |         | utf8mb4              | utf8mb4_0900_ai_ci   | utf8mb4_0900_ai_ci |
| Music | spAlbumsFromArtistName | PROCEDURE | root@localhost | 2021-11-13 13:03:48 | 2021-11-13 13:03:48 | DEFINER       |         | utf8mb4              | utf8mb4_0900_ai_ci   | utf8mb4_0900_ai_ci |
+-------+------------------------+-----------+----------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+

The information_schema.routines Table

Another way to get a list of stored procedures in MySQL is to query the information_schema.routines table.

Example:

SELECT 
    routine_schema as "Database",
    routine_name
FROM 
    information_schema.routines
WHERE 
    routine_type = 'PROCEDURE'
ORDER BY 
    routine_schema ASC, 
    routine_name ASC;

This table also stores information about stored functions. In the above example, I excluded those by using a WHERE clause to return only stored procedures (i.e. objects with a routine_type of PROCEDURE).

To include stored functions we can remove the WHERE clause:

SELECT 
    routine_schema as "Database",
    routine_name,
    routine_type
FROM 
    information_schema.routines
ORDER BY 
    routine_schema ASC, 
    routine_name ASC;

In this case I also added the routine_type column so that we can distinguish between the procedures and functions.

We can also exclude certain databases from the result:

SELECT 
    routine_schema as "Database",
    routine_name,
    routine_type
FROM 
    information_schema.routines
WHERE 
    routine_schema NOT IN ('sys', 'information_schema', 'mysql', 'performance_schema')
ORDER BY 
    routine_schema ASC, 
    routine_name ASC;

Here’s what this returns in my test environment:

+----------+------------------------+--------------+
| Database | ROUTINE_NAME           | ROUTINE_TYPE |
+----------+------------------------+--------------+
| Music    | spAlbumsByGenre        | PROCEDURE    |
| Music    | spAlbumsFromArtistId   | PROCEDURE    |
| Music    | spAlbumsFromArtistName | PROCEDURE    |
| Music    | spArtistFromId         | PROCEDURE    |
| PetHotel | spGetAllPets           | PROCEDURE    |
| PetHotel | spGetPetById           | PROCEDURE    |
+----------+------------------------+--------------+

We can also narrow it down to a specific database:

SELECT 
    routine_schema as "Database",
    routine_name,
    routine_type
FROM 
    information_schema.routines
WHERE 
    routine_schema = 'music'
ORDER BY 
    routine_name ASC;

Result:

+----------+------------------------+--------------+
| Database | ROUTINE_NAME           | ROUTINE_TYPE |
+----------+------------------------+--------------+
| Music    | spAlbumsByGenre        | PROCEDURE    |
| Music    | spAlbumsFromArtistId   | PROCEDURE    |
| Music    | spAlbumsFromArtistName | PROCEDURE    |
| Music    | spArtistFromId         | PROCEDURE    |
+----------+------------------------+--------------+