[文章作者:张宴 本文版本:v1.0 最后修改:2010.09.08 转载请注明原文链接:http://blog.zyan.cc/mysql-udf-http/]
Mysql-udf-http 是一款简单的MySQL用户自定义函数(UDF, User-Defined Functions),具有http_get()、http_post()、http_put()、http_delete()四个函数,可以在MySQL数据库中利用HTTP协议进行REST相关操作。
项目网址:http://code.google.com/p/mysql-udf-http/
中文说明:http://blog.zyan.cc/mysql-udf-http/
使用环境:Linux操作系统,支持的MySQL版本:5.1.x 和 5.5.x。5.0.x未经测试。
软件作者:张宴
一、REST架构风格:
REST(Representational State Transfer)是一种轻量级的Web Service架构风格,其实现和操作明显比SOAP和XML-RPC更为简洁,可以完全通过HTTP协议实现,还可以利用缓存Cache来提高响应速度,性能、效率和易用性上都优于SOAP协议。REST最早是由 Roy Thomas Fielding 博士2000年在论文《Architectural Styles and the Design of Network-based Software Architectures》中提出的,中文译文全文PDF点此下载。另外,有篇译文对REST做了一个简化说明。
目前,REST架构风格的常见实现是基于HTTP协议及其四种基本方法(如POST、GET、PUT和DELETE)的。有人将HTTP协议的四种方法与CRUD原则相对应,CRUD原则对于资源只需要四种行为:Create(创建)、Read(读取)、Update(更新)和Delete(删除)就可以完成对其操作和处理。
在Mysql-udf-http中,四个函数http_post()、http_get()、http_put()、http_delete()分别对应HTTP协议的POST、GET、PUT、DELETE四种方法。
REST是一种架构风格,而不是协议或标准。HTTP协议“POST、GET、PUT、DELET”四种方法与CRUD原则“Create、Read、Update、Delete”四种行为的一一对应关系只是一种架构设计习惯,而不是规范。因此,POST方法也可以用来更新资源,PUT方法也可以用来创建资源,这就要看具体应用程序作者的定义了。例如Tokyo Tyrant除了支持Memcached协议外,还支持REST方式存取,PUT代表创建和更新,GET代表读取,DELETE代表删除(关于Tokyo Tyrant的安装使用请点击这儿)。
目前国内外流行的Web 2.0应用API接口中,很多都支持REST架构风格。例如:新浪微博开放平台、人人网API、Google OpenID、Flickr、Twitter、eBay、Facebook、Last.fm、del.icio.us、Yahoo Search、Amazon S3、Amazon EC2、Digg、Microsoft Bing、FriendFeed、PayPal、Foursquare,更多...
当记录数成百上千万条时,通常采用 MySQL 分表减低数据库压力。但是,全部数据按点击数、精华、积分排序显示等功能,在MySQL 分表中则无法实现。编写 Mysql-udf-http 的最初目的,是为了在项目开发中,将 MySQL 各分表的数据自动同步到我们的 TCSQL 高速列表数据库,用来做列表查询、显示,内容页则根据ID直接查询各 MySQL 分表的内容。由于HTTP协议的通用性,通过 Mysql-udf-http 可以做更多的事情。
通过Mysql-udf-http,你可以在MySQL中利用触发器,将MySQL的数据同步到支持REST的应用上。例如你有一个独立博客,你可以在文章表创建MySQL触发器,这样,在发表文章时,就可以将文章标题、URL自动同步到新浪微博、Twitter。你想用 Tokyo Tyrant 做缓存,也可以利用MySQL触发器在发生增、删、改时,将数据自动同步到 Tokyo Tyrant。详细配置方法本文第4节中会有介绍。
二、Mysql-udf-http的安装与使用:
1. 在Linux系统上安装Mysql-udf-http
注意:“/usr/local/webserver/mysql/”是你的MySQL安装路径,如果你的MySQL安装路径不同,请自行修改。
2. 通过命令行登陆进入MySQL
3. 创建MySQL自定义函数
mysql>
4. 使用方法
I. 函数描述:
mysql>
II. 示例 A:
mysql>
III. 示例
通过MySQL触发器,利用mysql-udf-http和第三方UDF函数lib_mysqludf_json,自动同步数据到 Tokyo Tyrant。
(1). 下载安装 lib_mysqludf_json 修改版:
以下安装包适合32位Linux操作系统:
以下安装包适合64位Linux操作系统:
通过命令行登陆进入MySQL:
mysql> lib_mysqludf_json的详细用法请访问:http://www.mysqludf.org/lib_mysqludf_json/
(2). 创建测试表
mysql>
(3). 为测试表创建触发器:
mysql>
(4). 将 MySQL 表和 Tokyo Tyrant 关联进行查询:
mysql>
5. 如何删除mysql-udf-http UDF函数:
mysql>
Mysql-udf-http 是一款简单的MySQL用户自定义函数(UDF, User-Defined Functions),具有http_get()、http_post()、http_put()、http_delete()四个函数,可以在MySQL数据库中利用HTTP协议进行REST相关操作。
项目网址:http://code.google.com/p/mysql-udf-http/
中文说明:http://blog.zyan.cc/mysql-udf-http/
使用环境:Linux操作系统,支持的MySQL版本:5.1.x 和 5.5.x。5.0.x未经测试。
软件作者:张宴
一、REST架构风格:
REST(Representational State Transfer)是一种轻量级的Web Service架构风格,其实现和操作明显比SOAP和XML-RPC更为简洁,可以完全通过HTTP协议实现,还可以利用缓存Cache来提高响应速度,性能、效率和易用性上都优于SOAP协议。REST最早是由 Roy Thomas Fielding 博士2000年在论文《Architectural Styles and the Design of Network-based Software Architectures》中提出的,中文译文全文PDF点此下载。另外,有篇译文对REST做了一个简化说明。
目前,REST架构风格的常见实现是基于HTTP协议及其四种基本方法(如POST、GET、PUT和DELETE)的。有人将HTTP协议的四种方法与CRUD原则相对应,CRUD原则对于资源只需要四种行为:Create(创建)、Read(读取)、Update(更新)和Delete(删除)就可以完成对其操作和处理。
在Mysql-udf-http中,四个函数http_post()、http_get()、http_put()、http_delete()分别对应HTTP协议的POST、GET、PUT、DELETE四种方法。
REST是一种架构风格,而不是协议或标准。HTTP协议“POST、GET、PUT、DELET”四种方法与CRUD原则“Create、Read、Update、Delete”四种行为的一一对应关系只是一种架构设计习惯,而不是规范。因此,POST方法也可以用来更新资源,PUT方法也可以用来创建资源,这就要看具体应用程序作者的定义了。例如Tokyo Tyrant除了支持Memcached协议外,还支持REST方式存取,PUT代表创建和更新,GET代表读取,DELETE代表删除(关于Tokyo Tyrant的安装使用请点击这儿)。
目前国内外流行的Web 2.0应用API接口中,很多都支持REST架构风格。例如:新浪微博开放平台、人人网API、Google OpenID、Flickr、Twitter、eBay、Facebook、Last.fm、del.icio.us、Yahoo Search、Amazon S3、Amazon EC2、Digg、Microsoft Bing、FriendFeed、PayPal、Foursquare,更多...
当记录数成百上千万条时,通常采用 MySQL 分表减低数据库压力。但是,全部数据按点击数、精华、积分排序显示等功能,在MySQL 分表中则无法实现。编写 Mysql-udf-http 的最初目的,是为了在项目开发中,将 MySQL 各分表的数据自动同步到我们的 TCSQL 高速列表数据库,用来做列表查询、显示,内容页则根据ID直接查询各 MySQL 分表的内容。由于HTTP协议的通用性,通过 Mysql-udf-http 可以做更多的事情。
通过Mysql-udf-http,你可以在MySQL中利用触发器,将MySQL的数据同步到支持REST的应用上。例如你有一个独立博客,你可以在文章表创建MySQL触发器,这样,在发表文章时,就可以将文章标题、URL自动同步到新浪微博、Twitter。你想用 Tokyo Tyrant 做缓存,也可以利用MySQL触发器在发生增、删、改时,将数据自动同步到 Tokyo Tyrant。详细配置方法本文第4节中会有介绍。
二、Mysql-udf-http的安装与使用:
1. 在Linux系统上安装Mysql-udf-http
注意:“/usr/local/webserver/mysql/”是你的MySQL安装路径,如果你的MySQL安装路径不同,请自行修改。
ulimit -SHn 65535
wget http://curl.haxx.se/download/curl-7.21.1.tar.gz
tar zxvf curl-7.21.1.tar.gz
cd curl-7.21.1/
./configure --prefix=/usr
make && make install
cd ../
echo "/usr/local/webserver/mysql/lib/mysql/" > /etc/ld.so.conf.d/mysql.conf
/sbin/ldconfig
wget http://mysql-udf-http.googlecode.com/files/mysql-udf-http-1.0.tar.gz
tar zxvf mysql-udf-http-1.0.tar.gz
cd mysql-udf-http-1.0/
./configure --prefix=/usr/local/webserver/mysql --with-mysql=/usr/local/webserver/mysql/bin/mysql_config
make && make install
cd ../
wget http://curl.haxx.se/download/curl-7.21.1.tar.gz
tar zxvf curl-7.21.1.tar.gz
cd curl-7.21.1/
./configure --prefix=/usr
make && make install
cd ../
echo "/usr/local/webserver/mysql/lib/mysql/" > /etc/ld.so.conf.d/mysql.conf
/sbin/ldconfig
wget http://mysql-udf-http.googlecode.com/files/mysql-udf-http-1.0.tar.gz
tar zxvf mysql-udf-http-1.0.tar.gz
cd mysql-udf-http-1.0/
./configure --prefix=/usr/local/webserver/mysql --with-mysql=/usr/local/webserver/mysql/bin/mysql_config
make && make install
cd ../
2. 通过命令行登陆进入MySQL
/usr/local/webserver/mysql/bin/mysql -S /tmp/mysql.sock
3. 创建MySQL自定义函数
mysql>
4. 使用方法
I. 函数描述:
mysql>
II. 示例 A:
mysql>
III. 示例
通过MySQL触发器,利用mysql-udf-http和第三方UDF函数lib_mysqludf_json,自动同步数据到 Tokyo Tyrant。
(1). 下载安装 lib_mysqludf_json 修改版:
以下安装包适合32位Linux操作系统:
wget http://mysql-udf-http.googlecode.com/files/lib_mysqludf_json-i386.tar.gz
tar zxvf lib_mysqludf_json-i386.tar.gz
cd lib_mysqludf_json-i386/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/webserver/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
tar zxvf lib_mysqludf_json-i386.tar.gz
cd lib_mysqludf_json-i386/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/webserver/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
以下安装包适合64位Linux操作系统:
wget http://mysql-udf-http.googlecode.com/files/lib_mysqludf_json-x86_64.tar.gz
tar zxvf lib_mysqludf_json-x86_64.tar.gz
cd lib_mysqludf_json-x86_64/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/webserver/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
tar zxvf lib_mysqludf_json-x86_64.tar.gz
cd lib_mysqludf_json-x86_64/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/webserver/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
通过命令行登陆进入MySQL:
/usr/local/webserver/mysql/bin/mysql -S /tmp/mysql.sock
mysql> lib_mysqludf_json的详细用法请访问:http://www.mysqludf.org/lib_mysqludf_json/
(2). 创建测试表
mysql>
(3). 为测试表创建触发器:
mysql>
(4). 将 MySQL 表和 Tokyo Tyrant 关联进行查询:
mysql>
5. 如何删除mysql-udf-http UDF函数:
mysql>
Hibbah
2023-7-1 14:34
Appreciation for tracking down a valuable open door to look at that, I have a firm assessment on this subsequently really like getting to know leaning toward this kind of field. Do you mind invigorating your blog section with additional getting it? It should be really significant for all of us. cleaning hero
NBHGTT
2023-7-1 14:35
Appreciation for tracking down a valuable open door to look at that, I have a firm assessment on this subsequently really like getting to know leaning toward this kind of field. Do you mind invigorating your blog section with additional getting it? It should be really significant for all of us. cleaning hero
seo
2023-7-5 17:50
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free.Among the lots of comments on your articles. Thanks for sharing.I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. chatroulette
AHINS
2023-7-7 18:43
If "Ikaria Lean Belly Juice" is a new product, I recommend doing some research to gather more information about it. Look for official websites, customer reviews, and testimonials from reliable sources. Pay attention to the credibility of the sources and try to gather a balanced view of the product before making any purchasing decisions. IKARIA LEAN BELLY JUICE REVIEWS
seo
2023-7-11 13:09
You made a very good factor however I can not assist however wonder, what approximately the alternative side? !!!!!!Thanks ufabetทางเข้า
NBJHY
2023-7-11 18:05
If you don’t know much about big black dildo or don’t know how to choose – don’t worry – the following post outlines everything you want to know about big black dildo. huge black dildo
Hibbah
2023-7-12 18:12
However, when it comes to choosing any supplement, it's always recommended to consult with a healthcare professional or a registered dietitian who can provide personalized advice based on your individual needs and health conditions. SIGHT CARE
Hibah
2023-7-15 13:43
Its an extraordinary joy perusing your post.Its brimming with data I'm searching for and I love to post a remark that "The substance of your post is wonderful" Incredible work. domy na sprzedaz szklarska poreba
NBHYG
2023-7-20 18:11
In conclusion, Alpilean Reviews has undoubtedly emerged as a powerful tool for modern-day consumers. Its dedication to integrity, user-friendliness, and fostering a supportive community sets it apart from generic review platforms. So, the next time you're contemplating a purchase, don't forget to harness the collective wisdom of Alpilean Reviews and make well-informed choices that align with your needs and preferences. Happy reviewing! Alpilean reviews
ALams
2023-7-21 14:29
G2GBET is an online slot platform that offers a wide array of slot games for players to enjoy. To access these exciting slot games and make the most of your gaming experience, you need to learn how to log in to the G2GBET website slots. This step-by-step guide will walk you through the login process and help you get started with the thrilling world of online slot gaming. g2g เว็บตรง
JHUYS
2023-7-27 14:38
The nostalgia of classic Anekaslots is still appealing in today's modern gaming world. anekaslots
RDFGT
2023-7-28 19:00
Fast Lean Pro: Can it help with overall body strength? fast lean pro
Hibabh
2023-8-19 01:26
This timeless card game, renowned for its elegance and simplicity, has taken the betting world by storm, captivating the hearts of enthusiasts across the globe. Whether you're a seasoned gambler or a curious newcomer, the allure of baccarat is undeniable, offering an exhilarating experience that combines strategy, chance, and a touch of sophistication. บาคาร่าที่ดีที่สุด
Hibbah
2023-8-21 00:21
Veger offer multiple range of power bank including wireless power banks, power bank with inbuilt charging cables, high power and capacity power banks with PD/QC 3.0 technology for camping. Checkout their website to know more. Portable Power Banks
Hibah
2023-8-21 21:20
It is my first visit to your blog, and I am very impressed with the articles that you serve. Give adequate knowledge for me. Thank you for sharing useful material. I will be back for the more great post. raccoon control and removal
Hibbah
2023-8-23 17:37
Research is the cornerstone of progress, and having access to premium chemicals is a game-changer. Buy research chemicals Hungary
Hibbah
2023-8-31 19:55
The spa packages at STL Massage Spa are a great way to treat yourself or a loved one to a day of pampering. best spa in st louis
Hibnbhs
2023-9-3 13:42
In the realm of research methodologies, causal research holds a prominent position. It is the systematic investigation of cause-and-effect relationships, aiming to uncover the underlying mechanisms that drive specific outcomes. Causal research goes beyond merely observing correlations and delves into the intricacies of why and how certain phenomena occur. evaluation
Hibabh
2023-9-4 12:35
Hunting games have long held a special place in the world of video gaming, offering players a unique opportunity to experience the thrill of the hunt from the comfort of their own homes. Whether you're a seasoned hunter or someone who's never ventured into the woods, these games provide an exciting and immersive experience that allows you to track, stalk, and take down virtual prey. free hunting games
Hibbah
2023-9-7 18:17
Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. 빵실투어
分页: 12/24 7 8 9 10 11 12 13 14 15 16