mysql插件开发_mysql的插件开发记录
环境:
操作系统:window8.1
cygwin:x86_64
mysql:Generic Linux (Architecture Independent) 5.6.17
一、插件编写
1、创建目录
在mysql的插件源码目录(plugin)创建插件目录
2、编写代码
创建cc文件(c文件会导致编译错误),内容参考下面的源码
3、编写CMake文件
参考CMake文件
4、生成Make文件
回到mysql源码根目录,参考相关资料2中的生成makefile的操作
5、编译
进入1中目录,执行make命令
6、拷贝文件到mysql安装目录的lib/plugin
7、安装插件
INSTALL PLUGIN mytest SONAME 'TestJyx.dll';
其他操作:
1、展开宏定义,用于观察宏的定义
g++ -I/cygdrive/e/opensource/mysql/mysql-5.6.17-win/mysql-5.6.17/include -I/cygdrive/e/opensource/mysql/mysql-5.6.17-win/mysql-5.6.17/sql -DMYSQL_DYNAMIC_PLUGIN -E TestJyx.c > TestJyx.e
相关资料
1、http://www.hoterran.info/mysql-daemon-plugin-example
2、http://www.cnblogs.com/northhurricane/p/3665120.html
源码
/* This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/* follow mysql daemon_example.
Since GB code and UTF-8 code will lead conflict of displaying, I wiil use my poor English to comment.*/
#include "my_global.h"
#include "sql_priv.h"
#include "stdlib.h"
#include "ctype.h"
#include "mysql_version.h"
#include "mysql/plugin.h"
#include "my_dir.h"
#include "my_pthread.h" // pthread_handler_t
#include "my_sys.h" // my_write, my_malloc
#include "m_string.h" // strlen
#include "sql_plugin.h" // st_plugin_int. retrieve plugin runtime infomation
//record this plugin's infomation. Although we can use static variables, why not try this?
struct mytest_context
{
pthread_t mytest_thread; //thread of myself
};
char buffer[100];
char*
mytest_get_current_time()
{
time_t result;
struct tm tm_tmp;
result= time(NULL);
localtime_r(&result, &tm_tmp);
my_snprintf(buffer, sizeof(buffer),
"show me at %02d%02d%02d %2d:%02d:%02d\n",
tm_tmp.tm_year % 100,
tm_tmp.tm_mon+1,
tm_tmp.tm_mday,
tm_tmp.tm_hour,
tm_tmp.tm_min,
tm_tmp.tm_sec);
return buffer;
}
pthread_handler_t mytest_showme(void *p)
{
DBUG_ENTER("mytest_showme");
while(1)
{
sleep(5);
char *current_time = mytest_get_current_time();
fprintf(stderr, current_time);
}
DBUG_RETURN(0);
}
/*
Initialize this plugin at server start or plugin installation.
SYNOPSIS
mytest_plugin_init()
DESCRIPTION
Starts up mytest_showme thread
RETURN VALUE
0 success
1 failure (cannot happen)
*/
static int mytest_plugin_init(void *p)
{
DBUG_ENTER("mytest_plugin_init");
struct mytest_context *con;
pthread_attr_t attr; /* Thread attributes */
struct st_plugin_int *plugin= (struct st_plugin_int *)p;
con = (struct mytest_context *)
my_malloc(sizeof(struct mytest_context), MYF(0));
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,
PTHREAD_CREATE_JOINABLE);
/* now create the thread */
if (pthread_create(&con->mytest_thread, &attr, mytest_showme,
(void *)con) != 0)
{
fprintf(stderr,"Could not create heartbeat thread!\n");
DBUG_RETURN(1);
}
plugin->data= (void *)con;
fprintf(stderr,"Initialize success!\n");
DBUG_RETURN(0);
}
/*
Terminate this plugin at server shutdown or plugin deinstallation.
SYNOPSIS
mytest_plugin_deinit()
Does nothing.
RETURN VALUE
0 success
1 failure (cannot happen)
*/
static int mytest_plugin_deinit(void *p)
{
DBUG_ENTER("mytest_plugin_deinit");
struct st_plugin_int *plugin= (struct st_plugin_int *)p;
struct mytest_context *con=
(struct mytest_context *)plugin->data;
void *dummy_retval;
pthread_cancel(con->mytest_thread);
/*
Need to wait for the hearbeat thread to terminate before closing
the file it writes to and freeing the memory it uses
*/
pthread_join(con->mytest_thread, &dummy_retval);
my_free(con);
fprintf(stderr,"Deinitialize success!\n");
DBUG_RETURN(0);
}
struct st_mysql_daemon mytest_plugin=
{ MYSQL_DAEMON_INTERFACE_VERSION };
/*
Plugin library descriptor
*/
mysql_declare_plugin(daemon_example)
{
MYSQL_DAEMON_PLUGIN,
&mytest_plugin,
"mytest", /* the plugin name of sql "INSTALL PLUGIN plugin_name SONAME 'plugin_library'" */
"OldJ",
"Mytest, show info",
PLUGIN_LICENSE_GPL,
mytest_plugin_init, /* Plugin Init */
mytest_plugin_deinit, /* Plugin Deinit */
0x0100 /* 1.0 */,
NULL, /* status variables */
NULL, /* system variables */
NULL, /* config options */
0, /* flags */
}
mysql_declare_plugin_end;
CMakeLists.txt文件
MYSQL_ADD_PLUGIN(TestJyx TestJyx.cc
MODULE_ONLY MODULE_OUTPUT_NAME "TestJyx")
mysql插件开发_mysql的插件开发记录相关推荐
- mariadb mysql表_mysql/mariadb学习记录——创建删除数据库、表的基本命令
查看已有的数据库: mysql>show databases;+--------------------+ | Database | +--------------------+ | infor ...
- 1.登录mysql数据库_MySql使用全记录1 -----使用命令登录数据库
使用命令登录MySQL数据库 1 登录本机上的MySQL数据库(用户名:usr001, 口令:9876) 示例1 [root@localhost ~]#mysql -u usr001 -pEnter ...
- mysql中如何将一个表中的部分记录合并,MySQL数据库将多条记录的单个字段合并成一条记录_MySQL...
bitsCN.com MySQL数据库将多条记录的单个字段合并成一条记录 MySQL数据库将多条记录的单个字段合并成一条记录的操作是本文 我们主要要介绍的内容,接下来就让我们一起来了解一下这部分内容吧 ...
- mysql 记录所有操作_mysql 的一些记录的操作
①:删除表记录 用delete删除记录 DELETE 语句有如下格式: DELETE FROM tbl_name WHERE 要删除的记录 WHERE 子句指定哪些记录应该删除.它是可选的,但是如果不 ...
- 如何在mysql查询结果集中得到记录行号_MySQL中在查询结果集中得到记录行号的方法...
如果需要在查询语句返回的列中包含一列表示该条记录在整个结果集中的行号, ISO SQL:2003 标准提出的方法是提供 ROW_NUMBER() / RANK() 函数. Oracle 中可以使用标准 ...
- MariaDB/MySQL防止重复插入相同记录:INSERT IGNORE或者REPLACE
MySQL防止重复插入相同记录有2种常用的方法. 1 使用 INSERT IGNORE 使用 INSERT IGNORE 可以在插入具有相同主键的数据时不做重复插入. mysql> SELECT ...
- php django mysql配置文件_Mysql学习Django+mysql配置与简单操作数据库实例代码
<Mysql学习Django+mysql配置与简单操作数据库实例代码>要点: 本文介绍了Mysql学习Django+mysql配置与简单操作数据库实例代码,希望对您有用.如果有疑问,可以联 ...
- mysql max_allowed_packet 设置过小导致记录写入失败
mysql max_allowed_packet 设置过小导致记录写入失败 mysql根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会受max_allowed_packet 参 ...
- 高可用mysql笔记_MySQL笔记-高可用方案
MySQL笔记-高可用方案 一.概述 MYSQL高可用方案有多种,本次针对其中部分方案进行实践.包括主从,双主,myql+keepalived, mysql+mycat+keepalived. 纸上得 ...
最新文章
- JQuery 基础:8.节点操作
- SpringBatch 监听器之Job监听器(JobExecutionListener)和Step监听器(StepExecutionListener)(五)
- 人工智障学习笔记——机器学习(9)最大期望算法
- 洛谷——P1009 [NOIP1998 普及组] 阶乘之和
- 九度oj 题目1516:调整数组顺序使奇数位于偶数前面
- ofbiz中用 ajax 几点注意
- Hive MetaStore 配置
- linux dosbox使用教程,dosbox安装及汇编教程 dosbox的常用快捷键
- 黑帽seo技术大揭秘
- 基于android的健康管理系统客户端的设计与实现,基于Android的健康管理系统客户端的设计与实现...
- 一篇文章,读懂9种优先的管理之道
- python小甲鱼课后作业_小甲鱼python课后习题总结
- Flask入门教程——小白的艰难抗争史
- 怎样选择合适的ADC芯片
- 全局壁纸美化v3.0安卓版
- 第11章实验1:学生成绩管理系统V4.0(C语言)
- AFEchidna示例20--自交对方差分量的影响
- 猪八戒威客网对我的报道
- 灵格斯与金山词霸的细微差别
- 加入编译GMS包,增加或去除谷歌相关GMS应用,移除GMS包,取消刷机后的认证弹窗通知,锁fingerprint。
热门文章
- ubuntu 20 vlc源码编译
- 自动驾驶算法学习:多传感器信息融合(标定, 数据融合, 任务融合)
- 国科大学习资料–模式识别--复习要点
- 计算机最高单价公式,CFA考试中计算器的三种最高频率的用法
- PyQt5_股票K线形态查看工具
- “5G 将是一个彻底的失败通信技术” | 畅言
- 解决开始菜单出现的ms-resource:AppName异常
- 关于Minecraft Forge构建环境失败解决方法
- MTK6757的OTG线连接鼠标后,鼠标右键改为返回功能
- 2021年中国研究生数学建模竞赛C题帕金森病的脑深部电刺激治疗建模研究题目及思路参考代码