Common SQL Errors

MySQL Error 1128: ER_FUNCTION_NOT_DEFINED – How to Fix and Prevent

Galaxy Team
August 5, 2025

The server cannot find a user-defined or built-in function referenced in the query, triggering error 1128 (ER_FUNCTION_NOT_DEFINED).

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1128 (ER_FUNCTION_NOT_DEFINED)?

MySQL Error 1128: ER_FUNCTION_NOT_DEFINED occurs when the server cannot locate the referenced function. Verify the function name, ensure the correct database is selected, and create or install the missing routine to resolve the error.

Error Highlights

Typical Error Message

Function '%s' is not defined

Error Type

Runtime Error

Language

MySQL

Symbol

ER_FUNCTION_NOT_DEFINED

Error Code

1128

SQL State

Explanation

Table of Contents

What is MySQL Error 1128 (ER_FUNCTION_NOT_DEFINED)?

MySQL raises error 1128 when it encounters a function identifier that does not match any built-in, plugin, or stored function loaded in the current session. The message “Function '%s' is not defined” pinpoints the unknown routine.

The error halts execution immediately, so the rest of the query batch will not run. Resolving it quickly prevents application downtime and broken reports.

What Causes This Error?

A misspelled function name is the most frequent trigger.

MySQL treats function identifiers as case-insensitive on Windows but case-sensitive on Unix when the lower_case_table_names setting is 0.

Calling a stored function that exists in another database without qualifying it also causes the server to claim the function is undefined.

Removing or disabling plugins that previously registered custom functions leads to legacy SQL failing with error 1128.

How to Fix MySQL Error 1128

First, confirm the function name in INFORMATION_SCHEMA.ROUTINES or mysql.func if it is a UDF.

If no row matches, you must create or reinstall the routine.

If the routine exists in a different schema, fully qualify it (schema_name.function_name) or switch to that database with USE.

When the problem involves a missing plugin UDF, reinstall the library with INSTALL FUNCTION or restore the plugin file and restart MySQL.

Common Scenarios and Solutions

Analytics queries copied between environments often reference UDFs like regexp_substr that are only installed in production.

Install the same plugin in dev to fix.

Migrations that renamed a stored function without updating application code trigger the error.

Search and replace the old name across the codebase.

Best Practices to Avoid This Error

Maintain source control for all CREATE FUNCTION statements and deploy them alongside schema migrations.

Use Galaxy’s endorsed query library to track which functions each query relies on, preventing accidental deletions.

Set up automated tests that call critical routines after each deployment to catch missing functions early.

Related Errors and Solutions

Error 1305 (ER_SP_DOES_NOT_EXIST) occurs when a stored procedure cannot be found.

The fix process mirrors error 1128 but targets PROCEDURE objects.

Error 1064 (ER_PARSE_ERROR) signals general syntax issues that may hide an undefined function if the call is malformed.

.

Common Causes

Related Errors

FAQs

Does case sensitivity affect function lookup?

Yes. On Unix-like systems with lower_case_table_names set to 0, the function name is case sensitive. Match the exact case used during creation.

Can I disable a UDF temporarily?

You can drop the UDF with DROP FUNCTION but all queries referencing it will fail with error 1128 until it is reinstalled.

Why does the function work in production but not in staging?

Staging likely lacks the plugin or stored function. Sync routines between environments or include them in migration scripts.

How does Galaxy help avoid this error?

Galaxy’s AI autocompletion lists only valid functions from the connected database, reducing typos, and its Collections track dependencies so missing routines are caught early.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo