[文章作者:张宴 本文版本: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安装路径不同,请自行修改。

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 ../




  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 ../


  以下安装包适合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 ../


  通过命令行登陆进入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>





技术大类 » 数据库技术 | 评论(463) | 引用(0) | 阅读(193717)
seo Email
2023-3-11 23:12
Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.ThanksThis is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here!  스웨디시마사지
seo Email
2023-3-12 19:08
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.  Sotosum
seo Email
2023-3-13 17:42
When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your.Interesting topic for a blog. I have been searching the Internet for fun and came upon your website.I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article...Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject.i love reading this article so beautiful!!great job!  geldigheid VOG aanvragen
seo Email
2023-3-14 23:57
I'm always surprised via technique of technique for the quantity of data available on this subject. What you supplied grow to be accurately explored and accurately phrased with an quit purpose to get your replacement this throughout on your perusers in general.  topstarclinic
seoo Email
2023-3-15 19:56
I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info.This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work.  open source crowdfunding platform
seo
2023-3-16 05:23
I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,..I read a article under the same title some time ago, but this articles quality is much, much better. How you do this..  토토사이트
Hibbah Email
2023-3-16 18:19
Deneme bonusu veren siteler hem deneyimli hem de amatör oyuncular tarafından tercih edilen sitelerdir. Üyelerinin en iyi şekilde site içerisinde zaman geçirmesini isteyen platformlar üyelerine bedava deneme bonusu vermektedir. Bu bonuslar yatırımsızdır ve üyelerinin en iyi standartlarda oyun hizmeti alabilmesinde önemli bir yere sahiptir. Sitelerin üyelerine sunduğu avantajlar her siteye göre değişebilmektedir.  deneme bonusu
seo Email
2023-3-17 17:43
I can`t consider focusing lengthy sufficient to research; plenty much less write this sort of article. You`ve outdone your self with this material. This is extraordinary content material.  pgking168
seo Email
2023-3-21 04:29
I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… slot
seo
2023-3-22 06:09
You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers.  Website Design in Charlotte, NC
seo Email
2023-3-23 07:44
Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you.When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your.  Canlı Casino Siteleri
seoo Email
2023-3-27 03:49
Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..This is just the information I am finding everywhere.Admiring the time and effort you put into your blog and detailed information you offer!..Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome!You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this...   สล็อตออนไลน์
seo
2023-3-27 18:37
I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here.Nice knowledge gaining article. This post is really the best on this valuable topic.This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here!  rtp slot
seo Email
2023-3-28 17:31
I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.Thank you because you have been willing to share information with us.   บริษัทจัดหาคู่ Bangkok Matching
seo Email
2023-3-29 22:33
Pretty first-rate post. I simply stumbled upon your blog and desired to mention that I even have clearly loved surfing your weblog posts. After all I`ll be subscribing in your feed and I wish you write once more soon!  gclub
seo Email
2023-3-30 16:01
Admiring the time and effort you put into your blog and detailed information you offer!..Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!..I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.  https://bijibijidesign.com/
baccaratsite Homepage
2023-3-30 18:06
From some point on, I am preparing to build my site while browsing various sites. It is now somewhat completed. If you are interested, please come to play with  " "  !!     baccaratsite
seo
2023-4-3 10:29
I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well!the person who create this post it was a great human..thanks for shared this with us.Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome!  demo slot
seo Email
2023-4-4 21:19
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.Please continue this great work and I look forward to more of your awesome blog posts.It is a great website.. The Design looks very good.. Keep working like that!.  blooket
seo Email
2023-4-5 17:34
“FlyingTogether” is an online Employee Portal for United Airlines Employees. Using Flyingtogether, an Employee can Access and Manage many things such as Flight Schedules, Employee Benefits, Pay Stubs, and Tax Forms etc. Here’s How to Register and Login into FlyingTogether Portal easily.  Airfare changes regularly upon FlyingTogether.
分页: 7/24 第一页 上页 2 3 4 5 6 7 8 9 10 11 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]