Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.6Mb
PDF (A4) - 40.7Mb
PDF (RPM) - 40.3Mb
HTML Download (TGZ) - 10.7Mb
HTML Download (Zip) - 10.7Mb
HTML Download (RPM) - 9.3Mb
Man Pages (TGZ) - 243.0Kb
Man Pages (Zip) - 348.2Kb
Info (Gzip) - 3.9Mb
Info (Zip) - 3.9Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  /  ...  /  Installing and Uninstalling User-Defined Functions

5.7.1 Installing and Uninstalling User-Defined Functions

User-defined functions (UDFs) must be loaded into the server before they can be used. MySQL supports manual UDF loading at runtime and automatic loading during server startup.

While a UDF is loaded, information about it is available as described in Section 5.7.2, “Obtaining User-Defined Function Information”.

Installing User-Defined Functions

To load a UDF manually, use the CREATE FUNCTION statement. For example:

CREATE FUNCTION metaphon
  RETURNS STRING
  SONAME 'udf_example.so';

The UDF file base name depends on your platform. Common suffixes are .so for Unix and Unix-like systems, .dll for Windows.

CREATE FUNCTION has these effects:

Automatic UDF loading occurs during the normal server startup sequence:

  • UDFs registered in the mysql.func table are installed.

  • Server components or plugins that are installed at startup may automatically install related UDFs.

  • Automatic UDF installation adds the UDFs to the Performance Schema user_defined_functions table that provides runtime information about installed UDFs.

If the server is started with the --skip-grant-tables option, UDFs registered in the mysql.func table are not loaded and are unavailable. This does not apply to UDFs installed automatically by a component or plugin.

Uninstalling User-Defined Functions

To remove a UDF, use the DROP FUNCTION statement. For example:

DROP FUNCTION metaphon;

DROP FUNCTION has these effects:

  • It unloads the UDF to make it unavailable.

  • It removes the UDF from the mysql.func system table. For this reason, DROP FUNCTION requires the DELETE privilege for the mysql system database. With the UDF no longer registered in the mysql.func table, the server does not load the UDF during subsequent restarts.

  • It removes the UDF from the Performance Schema user_defined_functions table that provides runtime information about installed UDFs.

DROP FUNCTION cannot be used to drop a UDF that is installed automatically by server components or plugins rather than by using CREATE FUNCTION. Such a UDF is also dropped automatically, when the component or plugin that installed it is uninstalled.

Reinstalling or Upgrading User-Defined Functions

To reinstall or upgrade the shared library associated with a UDF, issue a DROP FUNCTION statement, upgrade the shared library, and then issue a CREATE FUNCTION statement. If you upgrade the shared library first and then use DROP FUNCTION, the server may unexpectedly shut down.