5.6 MySQL Server Loadable Functions

MySQL supports loadable functions, that is, functions that are not built in but can be loaded at runtime (either during startup or later) to extend server capabilities, or unloaded to remove capabilities. For a table describing the available loadable functions, see note loadable-function-reference::. Loadable functions contrast with built-in (native) functions, which are implemented as part of the server and are always available; for a table, see note built-in-function-reference::.

Note:

Loadable functions previously were known as user-defined functions (UDFs). That terminology was something of a misnomer because 'user-defined' also can apply to other types of functions, such as stored functions (a type of stored object written using SQL) and native functions added by modifying the server source code.

MySQL distributions include loadable functions that implement, in whole or in part, these server capabilities:

The following sections describe how to install and uninstall loadable functions, and how to determine at runtime which loadable functions are installed and obtain information about them.

For information about writing loadable functions, see Adding Functions to MySQL (https://dev.mysql.com/doc/extending-mysql/5.7/en/adding-functions.html).

 File: manual.info.tmp, Node: function-loading, Next: obtaining-loadable-function-information, Prev: server-loadable-functions, Up: server-loadable-functions

5.6.1 Installing and Uninstalling Loadable Functions

Loadable functions, as the name implies, must be loaded into the server before they can be used. MySQL supports automatic function loading during server startup and manual loading thereafter.

While a loadable function is loaded, information about it is available as described in *note obtaining-loadable-function-information::.

Installing Loadable Functions

To load a loadable function manually, use the *note 'CREATE FUNCTION': create-function-loadable. statement. For example:

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

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

*note 'CREATE FUNCTION': create-function-loadable. has these effects:

Automatic loading of loadable functions occurs during the normal server startup sequence. The server loads functions registered in the 'mysql.func' table. If the server is started with the '--skip-grant-tables' option, functions registered in the table are not loaded and are unavailable.

Uninstalling Loadable Functions

To remove a loadable function, use the *note 'DROP FUNCTION': drop-function-loadable. statement. For example:

 DROP FUNCTION metaphon;

*note 'DROP FUNCTION': drop-function-loadable. has these effects:

While a loadable function is loaded, information about it is available from the 'mysql.func' system table. See note obtaining-loadable-function-information::. note 'CREATE FUNCTION': create-function-loadable. adds the function to the table and *note 'DROP FUNCTION': drop-function-loadable. removes it.

Reinstalling or Upgrading Loadable Functions

To reinstall or upgrade the shared library associated with a loadable function, issue a note 'DROP FUNCTION': drop-function-loadable. statement, upgrade the shared library, and then issue a note 'CREATE FUNCTION': create-function-loadable. statement. If you upgrade the shared library first and then use *note 'DROP FUNCTION': drop-function-loadable, the server may unexpectedly shut down.

 File: manual.info.tmp, Node: obtaining-loadable-function-information, Prev: function-loading, Up: server-loadable-functions

5.6.2 Obtaining Information About Loadable Functions

The 'mysql.func' system table shows which loadable functions have been registered using *note 'CREATE FUNCTION': create-function.:

 SELECT * FROM mysql.func;

The 'func' table has these columns:

 File: manual.info.tmp, Node: multiple-servers, Next: debugging-mysql, Prev: server-loadable-functions, Up: server-administration