How to fix ERROR 1305: FUNCTION database.function doesn't exist in MySQL

MySQLBEGINNERMEDIUMUpdated Dec 25, 2025· 144 views

MySQL error 1305 occurs when you try to call a stored function that doesn't exist in the database. This commonly happens due to spaces between the function name and parentheses, incorrect database context, misspelled function names, or calling a stored procedure as a function.

Quick fix

Fixes 1305

SELECT DATABASE();
  1. Verify the current database context
  2. Check if the function exists
  3. Remove spaces between function name and parenthesis
  4. Use qualified function name with database
mysql — error
SELECT DATABASE();
ERROR 1305: FUNCTION database.function doesn't exist

What this error means

In MySQL, functions and stored procedures are distinct objects. A function must be called using SELECT statements and returns a value, while a procedure is called with CALL. Error 1305 (ER_SP_DOES_NOT_EXIST) indicates that MySQL cannot locate the requested function in the specified database schema. This error occurs at execution time when MySQL searches the current database (or specified database) for the function definition. If the function name doesn't match exactly—including case sensitivity on Unix systems, spelling, or if it's in a different database—MySQL throws this error.

Typical symptoms

  • SELECT query fails with "ERROR 1305: FUNCTION database.function doesn't exist"
  • Stored function calls work in one database but fail in another
  • Function works after recreating it but fails after server restart
  • Error appears when calling a function from a script or application
  • Using qualified name (database.function) still results in error 1305
  • Function exists but queries report it missing intermittently

Common causes

  1. Space between the function name and opening parenthesis (e.g., "IFNULL (" instead of "IFNULL(")
  2. Incorrect database context—not using the correct database before calling the function
  3. Misspelled function name or typo in the call statement
  4. Case sensitivity mismatch on Unix systems (lower_case_table_names=0)
  5. Calling a stored procedure as a function or vice versa
  6. Function not deployed or creation script failed silently
  7. User lacks EXECUTE or SELECT privilege on the function
  8. Function exists in a different database than the current one

How to fix "ERROR 1305: FUNCTION database.function doesn't exist"

1Verify the current database context

Ensure you are connected to the correct database:

sql
SELECT DATABASE();

If the result is NULL or shows a different database, switch to the correct one:

sql
USE your_database;

Always include an explicit USE statement before calling functions in production scripts.

2Check if the function exists

Query the information schema to verify the function exists:

sql
SELECT ROUTINE_NAME, ROUTINE_TYPE FROM information_schema.ROUTINES 
WHERE ROUTINE_SCHEMA = "your_database";

Or use the MySQL shorthand:

sql
SHOW FUNCTION STATUS WHERE Db = "your_database";

Note the exact spelling and case of the function name. If the function is not listed, it needs to be created.

3Remove spaces between function name and parenthesis

The most common cause is a space between the function name and the opening parenthesis. MySQL interprets this as a syntax error.

Incorrect:

sql
SELECT IFNULL (value, default_value) FROM table;
SELECT CONCAT (col1, col2) FROM table;

Correct:

sql
SELECT IFNULL(value, default_value) FROM table;
SELECT CONCAT(col1, col2) FROM table;

Update all function calls to remove the space before the parenthesis.

4Use qualified function name with database

If the function exists but error 1305 still occurs, try calling it with the full qualified name:

sql
SELECT database.function_name(arguments) FROM table;

For example:

sql
SELECT mydb.calculate_price(quantity, rate) FROM orders;

This ensures MySQL searches the correct database schema, bypassing any context confusion.

5Verify the function is called as a function, not a procedure

Confirm that you are calling a function in a SELECT statement, not a procedure. Procedures are called with CALL:

Function (returns a value, used in SELECT):

sql
SELECT my_function(col1) FROM table;

Procedure (does not return a value, uses CALL):

sql
CALL my_procedure(arg1, arg2);

If error 1305 mentions a procedure, switch to CALL syntax. If it mentions a function but you defined a procedure, recreate it as a function.

6Check case sensitivity on Unix systems

On Unix systems with lower_case_table_names=0, function names are case-sensitive. Check your MySQL configuration:

sql
SHOW VARIABLES LIKE 'lower_case_table_names';

If it returns 0 (case-sensitive), ensure your function call matches the exact case used in the CREATE FUNCTION statement:

sql
-- Created as:
CREATE FUNCTION CalculatePrice() ...

-- Must be called as:
SELECT CalculatePrice(...);

-- Not:
SELECT calculateprice(...);

On Windows (lower_case_table_names=1) and macOS (lower_case_table_names=2), function names are case-insensitive.

7Verify user privileges

The current user may lack EXECUTE privilege on the function. Check permissions:

sql
SELECT PRIVILEGE_TYPE FROM information_schema.ROLE_TABLE_GRANTS 
WHERE TABLE_NAME = "your_database";

Grant EXECUTE privilege if missing:

sql
GRANT EXECUTE ON FUNCTION your_database.my_function TO "app_user"@"localhost";
FLUSH PRIVILEGES;

Verify the user can execute the function:

sql
SELECT my_function(test_arg);
8Recreate the function if missing

If the function does not exist, create it from your application source code or schema definition:

sql
CREATE FUNCTION my_function(param1 INT) RETURNS INT
DETERMINISTIC
BEGIN
  RETURN param1 * 2;
END;

Include the DETERMINISTIC keyword for functions that return the same output for the same input. This enables MySQL to cache results.

After creating the function, verify it works:

sql
SELECT my_function(5);
9Test the function in your application context

After fixing the function call, test it in the environment where error 1305 occurred:

sql
USE your_database;
SELECT my_function(argument) FROM table LIMIT 1;

If using a connection pool or ORM (like Sequelize, SQLAlchemy), ensure the connection is established to the correct database before executing the query.

In application code:

javascript
// Node.js with mysql2
const result = await connection.query(
  "USE mydb; SELECT my_function(?) as result",
  [arg]
);

Advanced notes

Function name resolution: MySQL searches functions in the current database first. If a function shares the same name as a built-in function (like "substring"), always qualify the custom function: "database.my_substring()". Built-in functions are tried first, which can cause confusion.

Replicated environments: On master-slave replication, if the slave function creation fails, the slave will throw error 1305 when replication tries to execute the function. Check the slave status with "SHOW SLAVE STATUS;" and manually create missing functions on the slave.

For containerized MySQL: If using Docker or Kubernetes, ensure the initialization scripts (init.sql) include CREATE FUNCTION statements. Functions do not persist across container restarts unless created by the init process or stored in a mounted volume.

Performance: Limit use of functions in SELECT clauses on large result sets, as functions are called for every row. Use stored procedures with result tables or window functions for better performance.

Frequently asked questions

What does "1305" mean?
In MySQL, functions and stored procedures are distinct objects. A function must be called using SELECT statements and returns a value, while a procedure is called with CALL. Error 1305 (ER_SP_DOES_NOT_EXIST) indicates that MySQL cannot locate the requested function in the specified database schema.
How do I fix "1305"?
MySQL error 1305 occurs when you try to call a stored function that doesn't exist in the database. This commonly happens due to spaces between the function name and parentheses, incorrect database context, misspelled function names, or calling a stored procedure as a function.
What causes "1305"?
Space between the function name and opening parenthesis (e.g., "IFNULL (" instead of "IFNULL(") Incorrect database context—not using the correct database before calling the function Misspelled function name or typo in the call statement
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