8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

7.7.1 安装和卸载可加载函数7.7.1 Installing and Uninstalling Loadable Functions

可加载函数,顾名思义,必须先加载到服务器中才能使用。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”.

安装可加载函数Installing 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:

可加载函数的自动加载发生在正常的服务器启动过程中:Automatic loading of loadable functions occurs during the normal server startup sequence:

  • 在 mysql.func 表中注册的函数已安装。Functions registered in the mysql.func table 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 Schema user_defined_functions table 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.

卸载可加载函数Uninstalling Loadable Functions

要删除可加载函数,请使用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 the mysql.func system table. For this reason, DROP FUNCTION requires the DELETE privilege for the mysql system database. With the function no longer registered in the mysql.func table, the server does not load the function during subsequent restarts.

  • 它从 Performance Schema 的 user_defined_functions 表中移除该函数,该表提供已安装可加载函数的运行时信息。It removes the function from the Performance Schema user_defined_functions table 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.

重新安装或升级可加载函数Reinstalling or Upgrading Loadable Functions

要重新安装或升级与可加载函数关联的共享库,请执行 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.