MySQL & MariaDB error 1305: PROCEDURE or FUNCTION does not exist
FUNCTION t_0.ENCODE does not exist (8.0.46) A CALL or function call names a stored routine the server can't find in that database. Wrong database, a typo, a routine missing from the dump, or a space after a built-in function's name.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_SP_DOES_NOT_EXIST | ER_SP_DOES_NOT_EXIST |
| SQLSTATE | 42000 | 42000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
Stored procedures and functions belong to a database. CALL refresh_totals() looks in the current default database; shop.refresh_totals() looks in shop. 1305 means there is no routine of that name there.
Why it happens
- The routine lives in another database and the call isn’t qualified.
- The routine wasn’t copied:
mysqldumponly includes procedures and functions with--routines(-R), so a restored copy has the tables but not the routines. Triggers are included by default, routines are not. - A typo or a function that only exists in another product or version (MariaDB- or MySQL-only built-ins).
- A space between a built-in function name and its parenthesis, e.g.
COUNT (*), can make the parser treat it as a user function unlessIGNORE_SPACEis set, which gives this error or a syntax error. - The account lacks
EXECUTEand has no other privilege on the routine, so it can’t see it. That normally gives 1370 instead.
How to fix it
- Find it:
SELECT routine_schema, routine_name, routine_type FROM information_schema.ROUTINES WHERE routine_name = 'refresh_totals';. - Qualify the call:
CALL shop.refresh_totals();. - Back up with
mysqldump --routines --eventsso routines survive a restore.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database:CREATE DATABASE demo; USE demo;Run:
CALL refresh_totals();
You get: PROCEDURE t_0.refresh_totals does not exist(11.8.9)
Verified fixes
Find which database the routine lives in, then qualify the call
CREATE PROCEDURE refresh_totals() SELECT 1; SELECT routine_schema = DATABASE(), routine_type FROM information_schema.ROUTINES WHERE routine_name = 'refresh_totals';
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| CALL a procedure that isn't in the current database repro | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 |
| Call a function from another database without qualifying it (or a misspelt built-in) version check | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 | ✓ 1305 |
| Find which database the routine lives in, then qualify the call fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Related errors
Where this error shows up in our guides
- Stored function example · REGEXP_SUBSTR(product, '^.*[0-9]') with no function (MySQL 8.0+, MariaDB 10.0.5+) MySQL 5.6 5.7
- IFNULL(), NVL(), ISNULL(), NULLIF() and COALESCE() · NVL() (Oracle name) MySQL 5.6 5.7 8.0 8.4 9
- GROUP_CONCAT · JSON_ARRAYAGG alternative (modern) MySQL 5.6
- Removing linefeeds from text in a database · REGEXP_REPLACE(string, '[\r\n]+', '') (MySQL 8.0+, MariaDB 10.0.5+) MySQL 5.6 5.7
- Exporting/importing confidential information · ENCODE() to CSV, LOAD DATA with DECODE() (original) MySQL 8.0 8.4 9