简单管理mysql plugin
2013-04-25 16:51:36 阿炯

本站赞助商链接,请多关照。 MySQL从5.1开始引入了'plugin'概念,用于加载(运行时)相关的功能模块以实现、移除具体功能。来先看看MySQL逻辑架构:

MySQL最重要的、最与众不同的特性是它的存储引擎架构,这种构架的设计将查询处理及其它系统任务和数据的存储、提取相分离。

第一层,服务层,最上层的服务并不是MySQL独有的,大多数基于网络的客户端/服务端的工具或者服务都有类似的架构。主要为请求做连接处理,授权认证,安全等。

第二层,核心层,大多数MySQL的核心服务功能都在这一层,包括查询解析,分析,优化,缓存,以及所有的内置函数例如日期、时间、数学和加密函数,所有跨存储引擎的功能都在这一层实现:存储过程,触发器,视图等。

第三层,存储引擎,存储引擎负责MySQL中数据的存储和提取。服务器通过API与存储引擎进行通信。这些接口屏蔽了不同存储引擎之间的差异,使得这些差异对上层的查询过程透明。存储引擎不会去解析SQL,不同存储引擎之间也不会相互通信,而只是简单地响应上层服务的请求。


Plugins can be loaded at server startup, or loaded and unloaded at runtime without restarting the server. The API is generic and does not specify what plugins can do. The components supported by this interface include, but are not limited to, storage engines, full-text parser plugins, and server extensions.

For example, full-text parser plugins can be used to replace or augment the built-in full-text parser. A plugin can parse text into words using rules that differ from those used by the built-in parser. This can be useful if you need to parse text with characteristics different from those expected by the built-in parser.

The plugin interface is more general than the older user-defined function (UDF) interface.

The plugin interface uses the plugin table in the mysql database to record information about plugins that have been installed permanently with the INSTALL PLUGIN statement. This table is created as part of the MySQL installation process.

1、安装Plugin
语法如下: INSTALL PLUGIN plugin_name SONAME 'plugin_library'
mysql>INSTALL PLUGIN  Archive    SONAME 'ha_archive.so';
mysql>INSTALL PLUGIN  InnoDB    SONAME 'ha_innodb.so';

plugin_name 是在plugin声明中定义的plugin的名称,plugin名字大小写敏感可以由系统设置。plugin_library 是共享库的名字,共享库在 plugin的目录下,可能是静态或者动态库,如:libmyplugin.so or libmyplugin.dylib

共享库必须放在plugin目录下,目录是由plugin_dir系统变量中定义的,默认这个目录是由配置变量中的pkglibdir定义的,可以在服务器启动时候改变,比如可以在my.cnf中设置:
[mysqld]
plugin_dir=/path/to/plugin_dir

如果设置相对目录,目录是相对mysql base的系统变量。
INSTALL PLUGIN在mysql.plugin表中增加一行相关记录,同时INSTALL PLUGIN 会加载并初始化plugin。(To use INSTALL PLUGIN, you must have the INSERT privilege for the mysql.plugin table. )

在服务器启动的时候,服务器会加载所有plugin中的 plugin,也就是仅仅需要运行一次 INSTALL PLUGIN ,如果启动时候–skip-grant-tables ,则不会加载plugin。

服务器关闭的时候,会关闭plugin.

2、卸载plugin
语法如下:UNINSTALL PLUGIN plugin_name;
mysql>UNINSTALL PLUGIN  InnoDB;
plugin_name 是在plugin声明中定义的plugin的名称,plugin名字大小写敏感可以由系统设置。

3、显示已安装plugin
SHOW PLUGIN(老方法)可以看到所有的安装的plugin。
mysql>SHOW PLUGINS;
+--------------------------------+----------+--------------------+---------+---------+
| Name                           | Status   | Type               | Library | License |
+--------------------------------+----------+--------------------+---------+---------+
| binlog                         | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| partition                      | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| ARCHIVE                        | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| BLACKHOLE                      | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| CSV                            | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| FEDERATED                      | DISABLED | STORAGE ENGINE     | NULL    | GPL     |
......
| MyISAM                         | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| MRG_MYISAM                     | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
+--------------------------------+----------+--------------------+---------+---------+
31 rows in set (0.01 sec)

4、重新加载新的plugin共享库
如果重新编译了plugin共享库,可以选择以下两种方法之一:
4.1、卸载后重新安装

4.2、关闭服务器,覆盖文件,重新启动