Common SQL Errors

MySQL Error 1125: ER_UDF_EXISTS - Function already exists Fix Guide

Galaxy Team
August 5, 2025

MySQL raises error 1125 (ER_UDF_EXISTS) when a CREATE FUNCTION statement attempts to define a user-defined function with a name already registered in the same database.

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 code 1125?

MySQL Error 1125 ER_UDF_EXISTS appears when you run CREATE FUNCTION for a name that already exists in the current schema. Drop or rename the existing routine, or run the new function in a different database to solve the problem quickly.

Error Highlights

Typical Error Message

Function '%s' already exists

Error Type

Runtime Error

Language

MySQL

Symbol

ER_UDF_EXISTS

Error Code

1125

SQL State

Explanation

Table of Contents

What is MySQL Error 1125 ER_UDF_EXISTS?

MySQL throws error 1125 (SQLSTATE HY000) with the message Function 'name' already exists when you try to create a user-defined function that duplicates an existing routine name in the same database.

The server rejects the CREATE FUNCTION statement to avoid ambiguity during routine lookup. No function body is stored, and execution halts immediately.

What Causes This Error?

The error fires when any routine—UDF or stored function—already uses the target name in the selected database.

MySQL checks the INFORMATION_SCHEMA.ROUTINES table before compiling new code.

Case sensitivity depends on the lower_case_table_names setting, so names that differ only by case may still collide on many systems.

How to Fix MySQL Error 1125 ER_UDF_EXISTS

Confirm the conflicting routine with SHOW FUNCTION STATUS or a query against INFORMATION_SCHEMA.ROUTINES. Decide whether to drop, alter, or rename the existing object.

Use DROP FUNCTION IF EXISTS before CREATE FUNCTION, or choose a new, unique routine name.

In multi-schema environments, qualify the function with database name to avoid clashes.

Common Scenarios and Solutions

Deployment scripts often rerun CREATE FUNCTION without first cleaning old versions, triggering the error. Adding conditional drops fixes the pipeline.

During migrations, functions moved between databases can keep the same name. Explicitly switch databases with USE other_db or fully qualify the routine name.

Best Practices to Avoid This Error

Adopt a naming convention that prefixes functions with the team or module name.

This lowers the chance of future collisions.

Include DROP FUNCTION IF EXISTS in every migration file. Version-control functions in Git and review pull requests to spot duplicates early.

Related Errors and Solutions

Error 1304 ER_PROC_AUTO_REBIND fails when altering routines bound to invalid tables; recompile the routine after fixing table names.

Error 1303 ER_PROC_NOT_FOUND appears when calling a non-existent stored procedure; verify the routine name or database context.

.

Common Causes

Cause 1 – Duplicate UDF Name

A previous deployment already created a UDF with the same identifier, so the new CREATE FUNCTION conflicts immediately.

Cause 2 – Duplicate Stored Function

A standard stored function (not UDF) shares the name in the same schema.

MySQL treats both object types equally for uniqueness.

Cause 3 – Case-Insensitive Filesystem

On Windows or macOS with lower_case_table_names=1, MySQL normalizes routine names to lowercase, making Name() and name() equivalent.

Cause 4 – Forgotten DROP in CI/CD

Automated migration tools that run CREATE FUNCTION without conditional DROP repeatedly hit the error on every pipeline execution.

.

Related Errors

FAQs

Does dropping a UDF remove dependent views?

No. Dropping a UDF leaves views intact, but calls inside the view will fail until the function is recreated.

Is ER_UDF_EXISTS case sensitive?

On systems with lower_case_table_names=0 and case-sensitive filesystems, MySQL treats routine names as case sensitive. Otherwise, names collide regardless of case.

Can I ALTER FUNCTION to overwrite the old version?

MySQL lacks ALTER FUNCTION for UDFs. You must DROP FUNCTION and recreate it.

How does Galaxy help prevent duplicate functions?

Galaxy’s editor surfaces existing routine names in auto-complete and flags duplicates before you run the query, saving you from runtime errors.

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