How to fix ERROR 1305: Stored routine does not exist in MySQL
This error occurs when MySQL cannot locate a stored procedure or function you are trying to call. It is usually caused by a wrong database context, incorrect routine name, case sensitivity issues, or privilege problems.
Quick fix
Fixes 1305
SELECT DATABASE();
USE your_database_name;- Verify you are connected to the correct database
- Check that the stored routine exists
- Verify the exact routine name and syntax
- Use fully qualified names if the routine is in a different database
SELECT DATABASE();USE your_database_name;ERROR 1305: Stored routine does not exist
What this error means
When you execute a CALL statement for a stored procedure or use a stored function in a query, MySQL searches for that routine in the current database schema. Error 1305 (ER_SP_DOES_NOT_EXIST) means the server cannot find the routine by that name in that schema. This is MySQL's way of indicating that either: (1) the routine truly does not exist, (2) it exists in a different database than the one you are currently connected to, (3) the name or case does not match exactly, or (4) you lack EXECUTE permissions on that routine. It is important to distinguish between stored procedures (invoked with CALL) and stored functions (used in SELECT statements). Confusing the two will also trigger this error.
Typical symptoms
- MySQL returns "ERROR 1305 (42000): PROCEDURE/FUNCTION name does not exist"
- CALL statement fails when trying to invoke a procedure you created
- Application crashes or halts when a stored procedure cannot be found
- Works in production but fails in development due to schema differences
- CI/CD deployments fail because migrations did not create the stored procedure
Common causes
- Routine was never created or was dropped from the database
- You are connected to the wrong database or schema (wrong USE statement)
- The routine name has a typo or does not match the exact name in the database
- Case sensitivity mismatch on Unix systems where lower_case_table_names=0
- Calling a stored procedure with spaces between name and parentheses (e.g., FUNCTION (arg) instead of FUNCTION(arg))
- User lacks EXECUTE privilege on the stored routine
- Replication lag on a replica database where the routine has not yet been applied
- Database name contains special characters like dots, and the fully qualified name is not used
How to fix "ERROR 1305: Stored routine does not exist"
First, confirm you are using the right database:
SELECT DATABASE();
USE your_database_name;If you are connected to the wrong database, MySQL will search for the routine in that schema and not find it. Always ensure your session is in the correct database before calling a procedure.
Query the information_schema to verify the routine exists:
SELECT ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_SCHEMA
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_SCHEMA = DATABASE();Alternatively, use SHOW commands:
SHOW PROCEDURE STATUS WHERE db = DATABASE();
SHOW FUNCTION STATUS WHERE db = DATABASE();If the routine does not appear in the output, it either does not exist or is in a different database.
Ensure your CALL statement matches the exact name (including case) and syntax:
-- Correct (assuming proc_name exists)
CALL proc_name();
CALL proc_name(arg1, arg2);
-- Incorrect (spaces before parentheses)
CALL proc_name ();
CALL my_function (arg); -- Functions should use SELECT, not CALLRemember:
- Stored procedures are invoked with CALL
- Stored functions are used in SELECT statements or expressions
Using CALL on a function will fail with error 1305. Use: SELECT my_function(arg);
If the routine exists in a schema other than the current one, prefix the call with the database name:
CALL reporting.generate_report();
CALL analytics.process_data();This is especially useful in distributed environments or when working with multiple databases.
If the routine exists but you cannot execute it, verify your privileges:
-- Check what procedures a user can execute
SHOW GRANTS FOR 'username'@'hostname';
-- Grant EXECUTE privilege
GRANT EXECUTE ON PROCEDURE database_name.procedure_name TO 'username'@'hostname';
GRANT EXECUTE ON FUNCTION database_name.function_name TO 'username'@'hostname';
FLUSH PRIVILEGES;Without EXECUTE privilege, MySQL will report the routine as not existing (for security, it does not reveal whether the routine exists or if you simply lack permissions).
If the routine does not exist, you must recreate it. Retrieve the routine definition from source control or a backup:
DELIMITER //
CREATE PROCEDURE my_procedure(IN param1 INT, OUT result INT)
BEGIN
SELECT COUNT(*) INTO result FROM users WHERE id = param1;
END //
DELIMITER ;Then call it:
CALL my_procedure(1, @result);
SELECT @result;For deployments, ensure your SQL migration scripts include all CREATE PROCEDURE and CREATE FUNCTION statements.
On Unix-like systems, stored routine names are case-sensitive if lower_case_table_names=0. On Windows, they are case-insensitive.
-- Check the setting
SHOW VARIABLES LIKE 'lower_case_table_names';If lower_case_table_names=0, ensure your CALL statements match the routine name exactly:
-- If created as MyProcedure, must call as MyProcedure
CALL MyProcedure(); -- Correct
CALL myprocedure(); -- Error 1305 on UnixTo avoid this issue, always use lowercase for routine names across all platforms.
Advanced notes
Replication and lag: In replicated environments, if a stored procedure was recently created on the primary, it may not yet exist on a replica due to replication lag. Check the replica's Seconds_Behind_Master status. If lag exists, either wait for replication to catch up or execute the CREATE PROCEDURE on the replica directly.
Database names with special characters: If your database name contains dots or other special characters, use backticks or fully qualified names to avoid parsing issues. For example, if your database is named "my.db", use: CALL \my.db\.my_procedure();
MySQL 8.0 and ALTER ROUTINE: MySQL 8.0 does not support CREATE OR REPLACE PROCEDURE. Instead, drop and recreate: DROP PROCEDURE IF EXISTS my_proc; CREATE PROCEDURE my_proc(...) ...
Connector-specific issues: Some database connectors or drivers (e.g., MySQL Connector/NET, PHP mysqli) have quirks with stored procedures. Always clear empty result sets returned by procedures before executing the next query to avoid "queries while other unbuffered queries are active" errors.
Frequently asked questions
- What does "1305" mean?
- When you execute a CALL statement for a stored procedure or use a stored function in a query, MySQL searches for that routine in the current database schema. Error 1305 (ER_SP_DOES_NOT_EXIST) means the server cannot find the routine by that name in that schema. This is MySQL's way of indicating that either: (1) the routine truly does not exist, (2) it exists in a different database than the one you are currently connected to, (3) the name or case does not match exactly, or (4) you lack EXECUTE permissions on that routine.
- How do I fix "1305"?
- This error occurs when MySQL cannot locate a stored procedure or function you are trying to call. It is usually caused by a wrong database context, incorrect routine name, case sensitivity issues, or privilege problems.
- What causes "1305"?
- Routine was never created or was dropped from the database You are connected to the wrong database or schema (wrong USE statement) The routine name has a typo or does not match the exact name in the database
- Is the "1305" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐MySQL Official Documentation
- ๐MySQL Docs - Error Reference(Official Docs)
- ๐MySQL Docs - CALL Statement(Official Docs)