MySQL 5.1 開發儲存引擎相對便捷。本質上是依 MySQL 約定實現特定接口:插入記錄調用 write_row、索引檢索調用 index_read/index_next 等。核心接口由兩大結構定義:sql/handler.h 中的 handlerton 結構與 handler 類。
commit、rollback、savepoint 等)create、open、read、write、update、delete、index_init 等)struct st_mysql_storage_engine foo_storage_engine =
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
mysql_declare_plugin(foo)
{
MYSQL_STORAGE_ENGINE_PLUGIN,
&foo_storage_engine,
"FOO", // SHOW ENGINES 顯示名
"Author Here", // 作者
"Foo storage engine", // 說明
PLUGIN_LICENSE_GPL,
init_func, // 載入時調用
done_func, // 卸載時調用
0x0001, // 版本 0.1
NULL, NULL, NULL // 狀態/系統/配置變數
}
mysql_declare_plugin_end;
init_func,傳入 handlerton,引擎需設定 state、db_type、create、flags 等屬性(create 為函數指標,稍後被調用)。事務引擎還需設定事務接口函數指標。create 函數,引擎構建 handler 派生類實例並返回。原始碼 storage/example 目錄提供最小引擎 EXAMPLE 實現(僅能載入不可存儲)。新引擎開發最便捷方式:複製 example 代碼修改。