ERROR 1305 (42000): FUNCTION (or PROCEDURE) <name> does not exist is raised when MySQL cannot find a stored function or stored procedure with the given name in the current schema (or in the schema you specified). The error symbol is ER_SP_DOES_NOT_EXIST.
Impact
Any CALL statement invoking a nonexistent procedure, or any SELECT / SET using a nonexistent function, fails immediately and returns this error to the client. The statement is not executed; if the call is inside a multi-statement transaction, the rest of the transaction is not automatically rolled back (the transaction remains open), but the specific call fails.
Developers most often encounter this error immediately after a deployment that introduces a new routine — the routine was never created in the target environment — or after migrating a database to a new server where stored routines were not included in the dump. It also appears in ORMs and query builders that auto-call database functions: the ORM will surface the raw 1305 error code or wrap it in a driver exception such as com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException (Java/Connector/J) or MySQLdb.OperationalError (Python).
Common Causes
Typo in the routine name. Function and procedure names are case-insensitive on most platforms but must otherwise be spelled exactly. A call to
calcuate_total()instead ofcalculate_total()raises 1305.Wrong schema (database). The routine exists in a different database than the one currently selected.
USE mydb;followed byCALL reporting.generate_report();will work, butCALL generate_report();will not if the current database ismydband the routine lives inreporting.Routine was never created in this environment. The routine exists in development but the migration or dump that creates it was never run in staging or production. Stored routines are not included in a plain
mysqldumpunless--routinesis passed.Routine was dropped. A previous
DROP FUNCTIONorDROP PROCEDUREremoved the routine, or a schema re-creation wiped it out.Insufficient privileges to see the routine. Users without
EXECUTE(or in older MySQL versions, withoutSELECTonmysql.proc) may receive a 1305 even if the routine exists, because MySQL reports non-existence rather than a permission error in some contexts.Calling a built-in function with incorrect syntax. MySQL raises 1305 (not 1064) when you call a built-in function that exists but is invoked with a space between the name and the opening parenthesis — e.g.,
SELECT COUNT (*)raises this error whensql_modeincludesIGNORE_SPACE, causingCOUNTto be treated as a user-defined function name.
Troubleshooting and Resolution Steps
Confirm the routine exists and note its exact schema:
SELECT ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE FROM information_schema.ROUTINES WHERE ROUTINE_NAME = 'your_routine_name';If the query returns no rows, the routine does not exist in any accessible database and must be created.
Check which database is currently selected:
SELECT DATABASE();If the routine lives in a different schema, qualify the call:
CALL other_schema.your_procedure(); -- or for functions: SELECT other_schema.your_function(arg1, arg2);Re-create the missing routine. If the routine is missing from the target environment, run the
CREATE PROCEDUREorCREATE FUNCTIONstatement. When restoring from a dump, ensure--routineswas included:mysqldump --routines --single-transaction mydb > mydb.sql mysql mydb < mydb.sqlCheck privileges. Verify the connecting user has
EXECUTEon the routine:SHOW GRANTS FOR 'app_user'@'%';Grant if missing:
GRANT EXECUTE ON PROCEDURE mydb.your_procedure TO 'app_user'@'%'; FLUSH PRIVILEGES;Fix the IGNORE_SPACE / built-in function issue. If you are calling a built-in function and see 1305, check for a space between the function name and parenthesis:
-- Raises 1305 when IGNORE_SPACE is set: SELECT COUNT (*) FROM orders; -- Correct — no space: SELECT COUNT(*) FROM orders;Alternatively, remove
IGNORE_SPACEfromsql_modeif you do not need it.
Additional Information
- SQLSTATE 42000 is the "syntax error or access rule violation" class, shared with errors like 1064. MySQL maps 1305 here because calling a nonexistent routine is treated similarly to a syntax-level reference error.
- Related error codes:
1304 (ER_SP_ALREADY_EXISTS)is the opposite — raised when you try to create a routine that already exists withoutCREATE OR REPLACE/IF NOT EXISTS. Error1370 (ER_PROCACCESS_DENIED_ERROR)is raised when the routine exists but the user explicitly lacksEXECUTEprivilege. - mysqldump pitfall: By default,
mysqldumpdoes not export stored routines. Always use--routines(and--eventsfor scheduled events) to include them in backups. - MySQL 8.0+ change:
CREATE OR REPLACE PROCEDUREandCREATE PROCEDURE IF NOT EXISTSwere added in MySQL 8.0, making idempotent routine definitions easier in migration scripts. - Replication note: On replica servers, stored routines are replicated as DDL statements (in statement-based or mixed mode). If a routine is created on the primary but replication is lagging or has an error, the replica may raise 1305 until it catches up.
Frequently Asked Questions
Why does MySQL say the function doesn't exist when I can see it in Workbench?
You are most likely connected to a different schema in your application than in Workbench. Run SELECT DATABASE(); in your application session and compare it to the schema shown in Workbench. Either qualify the call with the schema name (schema.routine_name) or ensure both connections use the same default database.
I re-created the procedure but still get error 1305 — what else could be wrong?
Check that the CREATE PROCEDURE statement completed without error and that the routine is visible in information_schema.ROUTINES. Also confirm there are no typos in the name you are calling versus the name you created. If you are using a connection pool, old connections may be cached before the routine was created, though this should not affect DDL visibility once the routine is committed.
Does MySQL 1305 roll back my transaction?
No. The failed CALL or function reference returns an error to the client, but it does not automatically issue a ROLLBACK. Your application code is responsible for deciding whether to roll back or continue. Check your driver's autocommit setting and error-handling logic.
Why does SELECT COUNT (*) raise error 1305?
When IGNORE_SPACE is included in sql_mode, MySQL treats any identifier immediately followed by a space and then a parenthesis as a user-defined function call. COUNT is interpreted as a UDF name rather than the built-in aggregate function, and since no UDF named COUNT exists, you get error 1305. Remove the space — use COUNT(*) — to resolve it.