How long does a MySQL Function last?

If I write a Custom Function in MySQL, how long will it last?

Somewhere last night I read that it is only stored in memory and when you restart your database server all Functions are lost.

That seems kind of crazy?!

What is the truth?



By custom function, are you refering to UDFs? Typically you write them in C, then compile them into mysql, making them a permanent functionality.

Edit…sorry had a brainfart.

No, they are reloaded each time the server starts. You have to remove it manually with DROP FUNCTION

I don’t understand your response…

Let’s say I want to create a MySQL function called “funcCalculateSalesCommission(parameter list)”.

If I create a Stored Procedure, or Trigger, or a View in MySQL, then they all persist. Whether I shut down the MySQL database server or not, this database objects will always be there - just like my tables and data - as long as things do not become corrupt.

Logically, one would expect a Custom Function to persist in the same way.

It sounds like you are saying that is not the case, which if true, would be a really stupid design.

Follow me now?



Hey, not sure if you saw my edit yet ( post-brainfart ).

The functions that you create using the CREATE FUNCTION command are indeed persistent. All active functions get reloaded when the server starts up. They are removed only with DROP FUNCTION

Here found a link for you so that you can read it for yourself:

An active function is one that has been loaded with CREATE FUNCTION and not removed with DROP FUNCTION. All active functions are reloaded each time the server starts, unless you start mysqld with the --skip-grant-tables option.

Yes, I saw that, but the wording is throwing me some…

When I hear “get reloaded” it makes it sound like they disappear from the database.

(The webpage I was reading last night - but lost - said something like, “Every time you shut down MySQL, you have to manually reload all of your functions…”

To me, that implied that I would have to recreate every function in MySQL which would be insanity!)



Nope, they don’t disappear…since they are not native extensions, the sql server has to keep track of them and load them up when the server starts.
Think of it kind of like the database tables themselves…they will always exist once you create them, but you have to explicitly call them to use them. It’s the same with functions; you have to call them to use them, but they will always exist. The sql server just makes them accessible automatically once the server starts up…that’s what I meant by “reloading” them

Thanks for helping to clarify that.



P.S. Don’t turn this thread into a Microsoft discussion! (I think you meant MySQL database server and not “SQL Server”…) :wink: