0

0

Windows上的MySQL UDF开发_MySQL

php中文网

php中文网

发布时间:2016-06-01 14:06:24

|

1245人浏览过

|

来源于php中文网

原创

曾以为Windows版本的MySQL存在不能使用UDF的BUG诸提交了一个bug报告。不过
似乎发现是我搞错了,MySQL的技术支持人员给了非常完美的解答,同大家分享
一下。下边是原文回复 :)

Sorry this isn't a bug.
Below I pasted a sample I did sometime ago for another user:

Ok. Assuming you have VC and the source distribution and a server
running,
I will create a UDF that returns a name:

Note: the sample is ugly, but the purpose here is to show you how
to handle the UDF.

- Open the mysqld.dsw workspace.
- Add New project to the workspace
- Project name: my_udf
- Select Win32 Dynamic-Link Library
- Click OK
- Select An Empty DLL project
- Click Finish
- Click OK
- Add a new file called my_udf.cpp to the project:

#include
#include
#include

extern "C" {
char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error);
}

char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error)
{
char * me = "my name";

return me;
}

- Type Ctrl N for to create a new file.
- Select text type
- File name: my_udf.def
- Edit the above file with the below contents:
LIBRARY UDF_EXAMPLE
DESCRIPTION 'Example Using UDF with VC '
VERSION 1.0
EXPORTS
my_name

- Right Click the my_udf project and select Settings
- Click the C/C tab
- Select General in the Category Combo
- Add the macro HAVE_DLOPEN to the PreProcessor definition
- Select Preprocessor in the Category Combo
- Add the include path to the text box: Additional Include directories
e.g: ../include
- Press F7 for to build the DLL.

- Copy the my_udf.dll to the environment path directory:
\winnt\system32 for example.

- Start the mysql client and issue:

C:\mysql-udf\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.23.52-max-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE FUNCTION my_name RETURNS STRING SONAME "my_udf.dll";
Query OK, 0 rows affected (0.08 sec)

mysql> select my_name();

mysql> drop function my_name;
Query OK, 0 rows affected (0.00 sec)

画蛇添足的作下简要中文说明。

SmartB2B行业电子商务
SmartB2B行业电子商务

SmartB2B 是一款基于PHP、MySQL、Smarty的B2B行业电子商务网站管理系统,系统提供了供求模型、企业模型、产品模型、人才招聘模型、资讯模型等模块,适用于想在行业里取得领先地位的企业快速假设B2B网站,可以运行于Linux与Windows等多重服务器环境,安装方便,使用灵活。 系统使用当前流行的PHP语言开发,以MySQL为数据库,采用B/S架构,MVC模式开发。融入了模型化、模板

下载

抱歉,这并不是一个bug。下面我粘贴一个以前为某个客户做的简例,假设你有了
VC ,源码分发,并且有一个正常运行的MySQL服务器。

我将创建一个UDF它将一个名字:
注意:例子非常简陋,目的是让你了解该如何处理手头的UDF。

- 打开 mysqld.dsw 工作区。
- 添加新项目到这个工作区
- Project name: my_udf // 项目名称:my_udf
- 选择 Win32 Dynamic-Link Library // Win32动态连接库
- 点击 OK
- 选择 An Empty DLL project // 一个空DLL项目
- 点击 Finish
- 点击 OK
- 添加新文件 my_udf.cpp 到项目中:
#include
#include
#include

extern "C" {
char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error);
// 兼容C
}

char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error)
{
char * me = "my name";

return me;
// 调用此UDF将返回 my name
}
- 按 Ctrl N 来创建一个新文件。
- 选择 text 类型
- File name: my_udf.def file://文件名:my_udf.def
- 按照下边的内容编辑文件。
LIBRARY UDF_EXAMPLE
DESCRIPTION 'Example Using UDF with VC '
VERSION 1.0
EXPORTS
my_name

- 右击my_udf项目并选择Settings
- 点 C/C 选项卡
- 选择 General
- 添加宏 HAVE_DLOPE 到预处理器定义
- 选择 Preprocessor
- 添加头文件路径: Additional Include directories
例如: ../include
- 按 F7 去编译成 DLL.

- 复制 my_udf.dll 到环境变量path定义过的目录
比如 \winnt\system32 。

- 打开mysql客户端

C:\mysql-udf\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.23.52-max-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE FUNCTION my_name RETURNS STRING SONAME "my_udf.dll";
Query OK, 0 rows affected (0.08 sec)

mysql> select my_name();

mysql> drop function my_name;
Query OK, 0 rows affected (0.00 sec)


ok!欢迎大家来MySQL板交流UDF设计经验!我的电子邮件是HeartIcy@163.com,
手机13706410308。同时,我们MySQL板准备开始系统化持续性翻译MySQL文档,
希望大家多多支持共同完成这一项目。

HeartIcy
2003年5月17日于中国济南

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Node.js 教程
Node.js 教程

共57课时 | 7.2万人学习

Rust 教程
Rust 教程

共28课时 | 3.8万人学习

Vue 教程
Vue 教程

共42课时 | 5.4万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号