Mysql-udf-http 插件的安装与使用

 

1. 在Linux系统上安装Mysql-udf-http

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

mysql -uroot -proot

3. 创建MySQL自定义函数

create function http_get returns string soname 'mysql-udf-http.so';  
create function http_post returns string soname 'mysql-udf-http.so';  
create function http_put returns string soname 'mysql-udf-http.so';  
create function http_delete returns string soname 'mysql-udf-http.so';  

注意: 在执行上述create操作是,若提示如下错误

create function http_get returns string soname 'mysql-udf-http.so';ERROR 1127 (HY000): Can't find symbol 'http_get' in library

 

如果出现上述错误,原因是 /server/mysql/lib/plugin/mysql-udf-http.so 查看/server/mysql/lib/若存在mysql-udf-http.so.0.0.0则拷贝至plugin目录并更名为mysql-udf-http.so即可

 4. 示例 A:

/* HTTP GET、POST方式提交关键词“xoyo”到百度移动搜索 */  
SELECT http_get('http://m.baidu.com/s?word=xoyo&pn=0');  
SELECT http_post('http://m.baidu.com/s','word=xoyo&pn=0');  
  
/* 新浪微博开放平台:获取新浪用户ID为103500的最近一条微博内容 */  
SELECT http_get('http://api.t.sina.com.cn/statuses/user_timeline/103500.json?count=1&source=1561596835') AS data;  
/* 新浪微博开放平台:发表一条微博 */  
SELECT http_post('http://your_sina_uid:your_password@api.t.sina.com.cn/statuses/update.xml?source=1561596835', 'status=Thins is sina weibo test information');  
  
/* Tokyo Tyrant 写入、读取、删除操作 */  
SELECT http_put('http://192.168.8.34:1978/key', 'This is value');  
SELECT http_get('http://192.168.8.34:1978/key');  
SELECT http_delete('http://192.168.8.34:1978/key');  

 

本文参照: http://blog.s135.com/mysql-udf-http/2/1/

posted on 2013-10-23 16:33  lsl8966  阅读(3048)  评论(0编辑  收藏  举报