MySQL error 1305: the function you call does not exist
ERROR 1305 (42000): FUNCTION mydb.my_func does not existShort answer
Error 1305 means MySQL found no built-in, loadable or stored function with that name in the place it looked. Ask the server which stored functions exist and in which database. The usual causes are a function in another database, a restore that left routines out, or a name that is not a function in your MySQL version.
Fix it fast
1Find out which cause you have
List the stored functions with that name and see which database holds them. Note that the ROUTINES table does not list built-in or loadable functions, and an account only sees routines it has some privilege on. An empty result therefore means: no stored function of that name that your account can see.
SELECT ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION' AND ROUTINE_NAME = 'my_func';2Match what you see, then jump to its fix
- 1
The first-step query returns a row, but its ROUTINE_SCHEMA is not the database named in the error messageThe function lives in another database than the one you are inFix - 2
The first-step query returns no row anywhere, and the function worked on the source serverA restore or a dropped database removed the functionFix - 3
No row in ROUTINES for any database that your account can see, and the name is meant as a built-in function (a typo, or a function copied from another database system)The name is not a function in this MySQL version at allFix
- 1
What does the error look like?
ERROR 1305 (42000): FUNCTION mydb.my_func does not existError Code: 1305. FUNCTION mydb.my_func does not exist
Cause 1 of 3
The function lives in another database than the one you are in
1Check
A stored function belongs to one database. The manual says you can qualify a routine name with the database name to refer to a routine that is not in the current database. Compare the schema from the query with the current one.
SELECT DATABASE();
SELECT ROUTINE_SCHEMA, ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'my_func';2Fix
Call the function with the database name in front, or switch to the database that holds it before the call.
SELECT otherdb.my_func(42);
-- or
USE otherdb;
SELECT my_func(42);3Verify
The call returns a value instead of error 1305.
SELECT otherdb.my_func(42);Confirmed by dev.mysql.com
Cause 2 of 3
A restore or a dropped database removed the function
1Check
Stored routines go away with their database: dropping a database drops its routines. A dump contains routines only when --routines is used: the manual describes that option as including stored routines in the output, and for --all-databases in MySQL 8.4 it says to name --routines explicitly.
SELECT ROUTINE_SCHEMA, COUNT(*) FROM INFORMATION_SCHEMA.ROUTINES GROUP BY ROUTINE_SCHEMA;2Fix
Dump the database again from the source server with --routines, which adds the CREATE FUNCTION and CREATE PROCEDURE statements, and load that file. The option needs the global SELECT privilege.
mysqldump -u root -p --routines --databases mydb > mydb.sql
mysql -u root -p < mydb.sql3Verify
The first-step query now returns the function.
SELECT ROUTINE_SCHEMA, ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION';Confirmed by dev.mysql.com
Cause 3 of 3
The name is not a function in this MySQL version at all
1Check
MySQL reads an unqualified name as a built-in function if one exists, and otherwise as a loadable or stored function if one exists with that name. If none of the three exists, you get this error.
SELECT VERSION();
-- then look the name up in the manual's built-in function reference for that version2Fix
Use the documented built-in function with the right spelling for your version, or create your own stored function and call it with its database name.
-- built-in functions are listed here for each MySQL version:
-- https://dev.mysql.com/doc/refman/8.4/en/built-in-function-reference.html3Verify
The call runs without error 1305.
SELECT my_func(42);Confirmed by dev.mysql.com
How do I stop it coming back?
- Call your own functions with the database name in front, so a different default database does not break them.
- Dump with --routines, and --events if you use them, every time you copy a database; an --all-databases dump needs both in 8.4.
- After a restore, run the ROUTINES query above and compare the count with the source server.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
MySQL says execute command denied to user for routine
Execute command denied to user ''@'localhost' for routine
The account running CALL or the function has no EXECUTE privilege on that routine.
3 causes, each with a fixDatabases
A view, procedure or trigger names a DEFINER account that this server does not have
SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('app'@'%') does not exist
Views, stored routines, triggers and events remember the account that created them.
4 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fix