可加载函数,顾名思义,必须先加载到服务器中才能使用。MySQL 支持在服务器启动时自动加载函数,以及之后手动加载。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.
在可加载函数被加载时,有关它的信息可以按照第 7.7.2 节,“获取可加载函数的信息”中描述的方式获取。While a loadable function is loaded, information about it is available as described in Section 7.7.2, “Obtaining Information About Loadable Functions”.
要手动加载可加载函数,请使用 CREATE
FUNCTION 语句。例如:To load a loadable function manually, use the
CREATE
FUNCTION statement. For example:
CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
文件的基本名称取决于您的平台。常见的后缀是 Unix 和类 Unix 系统使用 .so,Windows 使用 .dll。The file base name depends on your platform. Common suffixes are
.so for Unix and Unix-like systems,
.dll for Windows.
CREATE
FUNCTION 具有以下效果:CREATE
FUNCTION has these effects:
它将函数加载到服务器中以立即使其可用。It loads the function into the server to make it available immediately.
它在
mysql.func系统表中注册该函数,以便在服务器重启后仍然保持持久。因此,CREATE FUNCTION需要对mysql系统数据库具有INSERT权限。It registers the function in themysql.funcsystem table to make it persistent across server restarts. For this reason,CREATE FUNCTIONrequires theINSERTprivilege for themysqlsystem database.它向性能模式
user_defined_functions表添加了一个功能,该表提供有关已安装可加载函数的运行时信息。参见 第 7.7.2 节,“获取有关可加载函数的信息”。It adds the function to the Performance Schemauser_defined_functionstable that provides runtime information about installed loadable functions. See Section 7.7.2, “Obtaining Information About Loadable Functions”.
可加载函数的自动加载发生在正常的服务器启动过程中:Automatic loading of loadable functions occurs during the normal server startup sequence:
在
mysql.func表中注册的函数已安装。Functions registered in themysql.functable are installed.在启动时安装的组件或插件可能会自动安装相关功能。Components or plugins that are installed at startup may automatically install related functions.
自动功能安装会将函数添加到性能模式
user_defined_functions表,该表提供关于已安装函数的运行时信息。Automatic function installation adds the functions to the Performance Schemauser_defined_functionstable that provides runtime information about installed functions.
如果服务器以 --skip-grant-tables 选项启动,则注册在 mysql.func 表中的函数不会被加载,并且不可用。这不适用于由组件或插件自动安装的函数。If the server is started with the
--skip-grant-tables option,
functions registered in the mysql.func table
are not loaded and are unavailable. This does not apply to
functions installed automatically by a component or plugin.
要删除可加载函数,请使用DROP
FUNCTION语句。例如:To remove a loadable function, use the
DROP
FUNCTION statement. For example:
DROP FUNCTION metaphon;
DROP
FUNCTION具有以下效果:DROP
FUNCTION has these effects:
它卸载该功能使其不可用。It unloads the function to make it unavailable.
它从
mysql.func系统表中移除该函数。因此,DROP FUNCTION需要对mysql系统数据库具有DELETE权限。由于该函数不再在mysql.func表中注册,服务器在随后的重启中不会加载该函数。It removes the function from themysql.funcsystem table. For this reason,DROP FUNCTIONrequires theDELETEprivilege for themysqlsystem database. With the function no longer registered in themysql.functable, the server does not load the function during subsequent restarts.它从 Performance Schema 的
user_defined_functions表中移除该函数,该表提供已安装可加载函数的运行时信息。It removes the function from the Performance Schemauser_defined_functionstable that provides runtime information about installed loadable functions.
DROP
FUNCTION 不能用于删除由组件或插件自动安装的可加载函数,而不是通过使用 CREATE
FUNCTION 安装的函数。这样的函数在安装它的组件或插件被卸载时也会自动删除。DROP
FUNCTION cannot be used to drop a loadable function
that is installed automatically by components or plugins rather
than by using
CREATE
FUNCTION. Such a function is also dropped
automatically, when the component or plugin that installed it is
uninstalled.
要重新安装或升级与可加载函数关联的共享库,请执行 DROP
FUNCTION 语句,升级共享库,然后执行 CREATE
FUNCTION 语句。如果您先升级共享库,然后再使用 DROP
FUNCTION,服务器可能会意外关闭。To reinstall or upgrade the shared library associated with a
loadable function, 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.