服务器插件必须先加载到服务器中才能使用。MySQL 支持在服务器启动和运行时加载插件。还可以在启动时控制已加载插件的激活状态,并在运行时卸载它们。Server plugins must be loaded into the server before they can be used. MySQL supports plugin loading at server startup and runtime. It is also possible to control the activation state of loaded plugins at startup, and to unload them at runtime.
当插件被加载时,有关它的信息可按照第 7.6.2 节,“获取服务器插件信息”中所述获取。While a plugin is loaded, information about it is available as described in Section 7.6.2, “Obtaining Server Plugin Information”.
在服务器插件可以使用之前,必须使用以下方法之一进行安装。在描述中,plugin_name 代表插件名称,例如 innodb、csv 或 validate_password。Before a server plugin can be used, it must be installed using
one of the following methods. In the descriptions,
plugin_name stands for a plugin name
such as innodb, csv, or
validate_password.
内置插件Built-in Plugins
服务器会自动识别内置插件。默认情况下,服务器在启动时启用该插件。某些内置插件允许使用 -- 选项更改此设置。A built-in plugin is known by the server automatically. By
default, the server enables the plugin at startup. Some built-in
plugins permit this to be changed with the
plugin_name[=activation_state]--
option.plugin_name[=activation_state]
在 mysql.plugin 系统表中注册的插件Plugins Registered in the mysql.plugin System Table
mysql.plugin 系统表用作插件的注册表(内置插件除外,内置插件无需注册)。在正常启动序列中,服务器会加载在表中注册的插件。默认情况下,对于从 mysql.plugin 表加载的插件,服务器也会启用该插件。可以通过 -- 选项进行更改。The plugin_name[=activation_state]mysql.plugin system table serves as a
registry of plugins (other than built-in plugins, which need not
be registered). During the normal startup sequence, the server
loads plugins registered in the table. By default, for a plugin
loaded from the mysql.plugin table, the
server also enables the plugin. This can be changed with the
--
option.plugin_name[=activation_state]
如果服务器使用 --skip-grant-tables 选项启动,则 mysql.plugin 表中注册的插件不会被加载,也不可用。If the server is started with the
--skip-grant-tables option,
plugins registered in the mysql.plugin table
are not loaded and are unavailable.
通过命令行选项指定的插件Plugins Named with Command-Line Options
位于插件库文件中的插件可以在服务器启动时通过 --plugin-load、--plugin-load-add 或 --early-plugin-load 选项加载。通常,对于在启动时加载的插件,服务器也会启用该插件。可以通过 -- 选项更改此设置。A plugin located in a plugin library file can be loaded at
server startup with the
plugin_name[=activation_state]--plugin-load,
--plugin-load-add, or
--early-plugin-load option.
Normally, for a plugin loaded at startup, the server also
enables the plugin. This can be changed with the
--
option.plugin_name[=activation_state]
--plugin-load 和 --plugin-load-add 选项在服务器启动序列中内置插件和存储引擎初始化之后加载插件。--early-plugin-load 选项用于加载必须在内置插件和存储引擎初始化之前可用的插件。The --plugin-load and
--plugin-load-add options load
plugins after built-in plugins and storage engines have
initialized during the server startup sequence. The
--early-plugin-load option is
used to load plugins that must be available prior to
initialization of built-in plugins and storage engines.
每个插件加载选项的值是由plugin_library和name=plugin_library值组成的分号分隔列表。每个plugin_library是包含插件代码的库文件的名称,每个name是要加载的插件名称。如果插件库仅以库名命名而没有前置插件名称,服务器将加载库中的所有插件。如果有前置插件名称,服务器将仅从库中加载指定的插件。服务器会在由plugin_dir系统变量指定的目录中查找插件库文件。The value of each plugin-loading option is a semicolon-separated
list of plugin_library and
name=plugin_library
values. Each plugin_library is the
name of a library file that contains plugin code, and each
name is the name of a plugin to load.
If a plugin library is named without any preceding plugin name,
the server loads all plugins in the library. With a preceding
plugin name, the server loads only the named plugin from the
library. The server looks for plugin library files in the
directory named by the
plugin_dir system variable.
插件加载选项不会在 mysql.plugin 表中注册任何插件。对于随后的重启,服务器仅在再次给出 --plugin-load、--plugin-load-add 或 --early-plugin-load 时才会再次加载插件。也就是说,该选项执行一次性插件安装操作,仅在单次服务器调用中有效。Plugin-loading options do not register any plugin in the
mysql.plugin table. For subsequent restarts,
the server loads the plugin again only if
--plugin-load,
--plugin-load-add, or
--early-plugin-load is given
again. That is, the option produces a one-time
plugin-installation operation that persists for a single server
invocation.
--plugin-load、--plugin-load-add 和 --early-plugin-load 允许即使在指定 --skip-grant-tables 时也能加载插件(这会导致服务器忽略 mysql.plugin 表)。--plugin-load、--plugin-load-add 和 --early-plugin-load 也允许在启动时加载那些运行时无法加载的插件。--plugin-load,
--plugin-load-add, and
--early-plugin-load enable
plugins to be loaded even when
--skip-grant-tables is given
(which causes the server to ignore the
mysql.plugin table).
--plugin-load,
--plugin-load-add, and
--early-plugin-load also enable
plugins to be loaded at startup that cannot be loaded at
runtime.
--plugin-load-add 选项补充了 --plugin-load 选项:The --plugin-load-add option
complements the --plugin-load
option:
每个
--plugin-load实例都会重置在启动时要加载的插件集合,而--plugin-load-add会向要加载的插件集合中添加一个或多个插件而不重置当前集合。因此,如果指定了多个--plugin-load实例,只有最后一个会生效。对于多个--plugin-load-add实例,它们都将生效。Each instance of--plugin-loadresets the set of plugins to load at startup, whereas--plugin-load-addadds a plugin or plugins to the set of plugins to be loaded without resetting the current set. Consequently, if multiple instances of--plugin-loadare specified, only the last one applies. With multiple instances of--plugin-load-add, all of them apply.参数格式与
--plugin-load相同,但可以使用多个--plugin-load-add实例,以避免将大量插件作为单个冗长且难以处理的--plugin-load参数进行指定。The argument format is the same as for--plugin-load, but multiple instances of--plugin-load-addcan be used to avoid specifying a large set of plugins as a single long unwieldy--plugin-loadargument.--plugin-load-add可以在没有--plugin-load的情况下使用,但任何出现在--plugin-load之前的--plugin-load-add都不会生效,因为--plugin-load会重置要加载的插件集合。--plugin-load-addcan be given in the absence of--plugin-load, but any instance of--plugin-load-addthat appears before--plugin-loadhas no effect because--plugin-loadresets the set of plugins to load.
例如,这些选项:For example, these options:
--plugin-load=x --plugin-load-add=y
等同于这些选项:are equivalent to these options:
--plugin-load-add=x --plugin-load-add=y
也等同于这个选项:and are also equivalent to this option:
--plugin-load="x;y"
但这些选项:But these options:
--plugin-load-add=y --plugin-load=x
相当于此选项:are equivalent to this option:
--plugin-load=x
使用 INSTALL PLUGIN 语句安装的插件Plugins Installed with the INSTALL PLUGIN Statement
位于插件库文件中的插件可以在运行时通过 INSTALL PLUGIN 语句加载。该语句还会在 mysql.plugin 表中注册该插件,以便服务器在后续重启时加载它。因此,INSTALL PLUGIN 需要对 mysql.plugin 表具有 INSERT 权限。A plugin located in a plugin library file can be loaded at
runtime with the INSTALL PLUGIN
statement. The statement also registers the plugin in the
mysql.plugin table to cause the server to
load it on subsequent restarts. For this reason,
INSTALL PLUGIN requires the
INSERT privilege for the
mysql.plugin table.
插件库文件的基本名称取决于您的平台。常见的后缀是 .so 用于 Unix 和类 Unix 系统,.dll 用于 Windows。The plugin library file base name depends on your platform.
Common suffixes are .so for Unix and
Unix-like systems, .dll for Windows.
示例:--plugin-load-add 选项在服务器启动时安装插件。要从名为 somepluglib.so 的插件库文件安装名为 myplugin 的插件,可在 my.cnf 文件中使用以下内容:Example: The --plugin-load-add
option installs a plugin at server startup. To install a plugin
named myplugin from a plugin library file
named somepluglib.so, use these lines in a
my.cnf file:
[mysqld] plugin-load-add=myplugin=somepluglib.so
在这种情况下,插件不会在 mysql.plugin 中注册。如果在没有 --plugin-load-add 选项的情况下重启服务器,则插件不会在启动时加载。In this case, the plugin is not registered in
mysql.plugin. Restarting the server without
the --plugin-load-add option
causes the plugin not to be loaded at startup.
或者,INSTALL PLUGIN 语句会导致服务器在运行时从库文件加载插件代码:Alternatively, the INSTALL PLUGIN
statement causes the server to load the plugin code from the
library file at runtime:
INSTALL PLUGIN myplugin SONAME 'somepluglib.so';
INSTALL PLUGIN 还会导致“永久” 插件注册:该插件会被列在 mysql.plugin 表中,以确保服务器在后续重启时加载它。INSTALL PLUGIN also causes
“permanent” plugin registration: The plugin is
listed in the mysql.plugin table to ensure
that the server loads it on subsequent restarts.
许多插件可以在服务器启动时或运行时加载。然而,如果一个插件的设计要求它必须在服务器启动时加载和初始化,则在运行时尝试使用 INSTALL
PLUGIN 加载它会产生错误:Many plugins can be loaded either at server startup or at
runtime. However, if a plugin is designed such that it must be
loaded and initialized during server startup, attempts to load
it at runtime using INSTALL
PLUGIN produce an error:
mysql> INSTALL PLUGIN myplugin SONAME 'somepluglib.so';
ERROR 1721 (HY000): Plugin 'myplugin' is marked as not dynamically
installable. You have to stop the server to install it.
在这种情况下,您必须使用 --plugin-load、--plugin-load-add 或 --early-plugin-load。In this case, you must use
--plugin-load,
--plugin-load-add, or
--early-plugin-load.
如果一个插件既通过 --plugin-load、--plugin-load-add 或 --early-plugin-load 选项命名,又由于之前的 INSTALL
PLUGIN 语句已存在于 mysql.plugin 表中,服务器启动时会写入这些消息到错误日志:If a plugin is named both using a
--plugin-load,
--plugin-load-add, or
--early-plugin-load option and
(as a result of an earlier INSTALL
PLUGIN statement) in the
mysql.plugin table, the server starts but
writes these messages to the error log:
[ERROR] Function 'plugin_name' already exists [Warning] Couldn't load plugin named 'plugin_name' with soname 'plugin_object_file'.
如果服务器在启动时知道某个插件(例如,因为插件使用 --plugin-load-add 选项命名,或者在 mysql.plugin 表中注册),服务器默认会加载并启用该插件。可以使用 -- 启动选项来控制此类插件的激活状态,其中 plugin_name[=activation_state]plugin_name 是要影响的插件名称,例如 innodb、csv 或 validate_password。与其他选项一样,选项名称中的连字符和下划线可以互换。此外,激活状态值不区分大小写。例如,--my_plugin=ON 和 --my-plugin=on 是等价的。If the server knows about a plugin when it starts (for example,
because the plugin is named using a
--plugin-load-add option or is
registered in the mysql.plugin table), the
server loads and enables the plugin by default. It is possible
to control activation state for such a plugin using a
--
startup option, where plugin_name[=activation_state]plugin_name is
the name of the plugin to affect, such as
innodb, csv, or
validate_password. As with other options,
dashes and underscores are interchangeable in option names.
Also, activation state values are not case-sensitive. For
example, --my_plugin=ON and
--my-plugin=on are equivalent.
--plugin_name=OFF--plugin_name=OFF告诉服务器禁用该插件。使用此选项,您可以在服务器启动时禁用例如已弃用的
mysql_native_password插件。Tells the server to disable the plugin. Using this option, you can disable, for example, the deprecatedmysql_native_passwordplugin at server startup.--plugin_name[=ON]--plugin_name[=ON]告诉服务器启用该插件。(将选项指定为
--而不带值具有相同效果。)如果插件初始化失败,服务器将以禁用该插件的方式运行。Tells the server to enable the plugin. (Specifying the option asplugin_name--without a value has the same effect.) If the plugin fails to initialize, the server runs with the plugin disabled.plugin_name--plugin_name=FORCE--plugin_name=FORCE告诉服务器启用插件,但如果插件初始化失败,服务器将不会启动。换句话说,此选项强制服务器在启用插件的情况下运行,否则根本无法运行。Tells the server to enable the plugin, but if plugin initialization fails, the server does not start. In other words, this option forces the server to run with the plugin enabled or not at all.
--plugin_name=FORCE_PLUS_PERMANENT--plugin_name=FORCE_PLUS_PERMANENT类似于
FORCE,但此外还会防止在运行时卸载插件。如果用户尝试使用UNINSTALL PLUGIN进行卸载,将会发生错误。LikeFORCE, but in addition prevents the plugin from being unloaded at runtime. If a user attempts to do so withUNINSTALL PLUGIN, an error occurs.
插件激活状态可以在信息模式中的LOAD_OPTION列看到,参见PLUGINS表。Plugin activation states are visible in the
LOAD_OPTION column of the Information Schema
PLUGINS table.
假设 CSV、BLACKHOLE 和 ARCHIVE 是内置的可插拔存储引擎,并且你希望服务器在启动时加载它们,但需满足以下条件:如果 CSV 初始化失败,服务器仍允许运行;必须确保 BLACKHOLE 初始化成功;并且应该禁用 ARCHIVE。为实现这一点,在选项文件中使用以下几行:Suppose that CSV,
BLACKHOLE, and ARCHIVE are
built-in pluggable storage engines and that you want the server
to load them at startup, subject to these conditions: The server
is permitted to run if CSV initialization
fails, must require that BLACKHOLE
initialization succeeds, and should disable
ARCHIVE. To accomplish that, use these lines
in an option file:
[mysqld] csv=ON blackhole=FORCE archive=OFF
--enable- 选项格式是 plugin_name-- 的同义词。plugin_name=ON--disable- 和 plugin_name--skip- 选项格式是 plugin_name-- 的同义词。The
plugin_name=OFF--enable-
option format is a synonym for
plugin_name--.
The
plugin_name=ON--disable-
and
plugin_name--skip-
option formats are synonyms for
plugin_name--.plugin_name=OFF
如果插件被禁用,无论是通过 OFF 明确禁用,还是因为以 ON 启用但初始化失败而隐式禁用,服务器操作中依赖该插件的部分就会发生变化。例如,如果该插件实现了一个存储引擎,那么现有的该存储引擎的表将无法访问,并且尝试为该存储引擎创建新表将会生成使用默认存储引擎的表,除非启用了 NO_ENGINE_SUBSTITUTION SQL 模式,使其改为报错。If a plugin is disabled, either explicitly with
OFF or implicitly because it was enabled with
ON but fails to initialize, aspects of server
operation requiring the plugin change. For example, if the
plugin implements a storage engine, existing tables for the
storage engine become inaccessible, and attempts to create new
tables for the storage engine result in tables that use the
default storage engine unless the
NO_ENGINE_SUBSTITUTION SQL
mode is enabled to cause an error to occur instead.
禁用插件可能需要调整其他选项。Disabling a plugin may require adjustment to other options.
在运行时,UNINSTALL PLUGIN 语句会禁用并卸载服务器已知的插件。该语句会卸载插件并将其从 mysql.plugin 系统表中移除(如果插件已在该表中注册)。因此,UNINSTALL PLUGIN 语句需要对 mysql.plugin 表具有 DELETE 权限。在插件不再在表中注册后,服务器在随后的重启中不会加载该插件。At runtime, the UNINSTALL PLUGIN
statement disables and uninstalls a plugin known to the server.
The statement unloads the plugin and removes it from the
mysql.plugin system table, if it is
registered there. For this reason,
UNINSTALL PLUGIN statement
requires the DELETE privilege for
the mysql.plugin table. With the plugin no
longer registered in the table, the server does not load the
plugin during subsequent restarts.
UNINSTALL PLUGIN 可以卸载插件,无论它是在运行时通过 INSTALL PLUGIN 加载的,还是在启动时通过插件加载选项加载的,但需满足以下条件:UNINSTALL PLUGIN can unload a
plugin regardless of whether it was loaded at runtime with
INSTALL PLUGIN or at startup with
a plugin-loading option, subject to these conditions:
它无法卸载内置于服务器的插件。这些插件可以通过在信息模式
PLUGINS表的输出中查看库名称为NULL或通过SHOW PLUGINS来识别。It cannot unload plugins that are built in to the server. These can be identified as those that have a library name ofNULLin the output from the Information SchemaPLUGINStable orSHOW PLUGINS.无法卸载服务器以
--启动的插件,这会阻止在运行时卸载插件。这些插件可以从plugin_name=FORCE_PLUS_PERMANENTPLUGINS表的LOAD_OPTION列中识别出来。It cannot unload plugins for which the server was started with--, which prevents plugin unloading at runtime. These can be identified from theplugin_name=FORCE_PLUS_PERMANENTLOAD_OPTIONcolumn of thePLUGINStable.
要卸载当前使用插件加载选项在服务器启动时加载的插件,请使用此步骤。To uninstall a plugin that currently is loaded at server startup with a plugin-loading option, use this procedure.
从
my.cnf文件中移除与插件相关的任何选项和系统变量。如果有任何插件系统变量被持久化到mysqld-auto.cnf文件中,请使用RESET PERSIST var_name对每个变量进行移除。Remove from themy.cnffile any options and system variables related to the plugin. If any plugin system variables were persisted to themysqld-auto.cnffile, remove them usingRESET PERSISTfor each one to remove it.var_name重启服务器。Restart the server.
插件通常通过在启动时使用插件加载选项或在运行时使用
INSTALL PLUGIN来安装,但不能两者同时使用。然而,如果在某个时候曾使用过INSTALL PLUGIN,仅从my.cnf文件中删除插件的选项可能不足以卸载它。如果插件仍出现在PLUGINS或SHOW PLUGINS的输出中,请使用UNINSTALL PLUGIN将其从mysql.plugin表中删除。然后再次重启服务器。Plugins normally are installed using either a plugin-loading option at startup or withINSTALL PLUGINat runtime, but not both. However, removing options for a plugin from themy.cnffile may not be sufficient to uninstall it if at some pointINSTALL PLUGINhas also been used. If the plugin still appears in the output fromPLUGINSorSHOW PLUGINS, useUNINSTALL PLUGINto remove it from themysql.plugintable. Then restart the server again.