给MySQL增加mysql-udf-http和mysql-udf-json自定义函数,让MySQL有调用http接口和查询直接回JSON的能力...

1、安装mysql-udf-http
yum install -y libcurl*
下载地址:http://pan.baidu.com/s/1nuYZqR3
tar zxvf mysql-udf-http-1.0.tar.gz
cd mysql-udf-http-1.0
./configure --prefix=/usr/local/mysql-udf-http --with-mysql=/usr/local/mysql/bin/mysql_config
make && make install
ln -s /usr/local/mysql-udf-http/lib/mysql-udf-http.so.0.0.0 /usr/local/mysql/lib/plugin/mysql-udf-http.so
service mysql restart

#删除
DROP FUNCTION IF EXISTS http_get;
DROP FUNCTION IF EXISTS http_post;
DROP FUNCTION IF EXISTS http_put;
DROP FUNCTION IF EXISTS http_delete;
#创建
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';

实例:
select http_get('http://10.10.3.199/dsideal_yy/kgdxpr') as res;
select http_post('http://10.10.3.199/dsideal_yy/kgdxpr','id=1&type=a') as res;

 

2、安装mysql-udf-json

下载地址:http://pan.baidu.com/s/1pLtnXDT
unzip lib_mysqludf_json-master.zip
cd lib_mysqludf_json-master
gcc $(mysql_config --cflags) -shared -fPIC -o lib_mysqludf_json.so lib_mysqludf_json.c
cp lib_mysqludf_json.so /usr/local/mysql/lib/plugin/

#删除
DROP FUNCTION IF EXISTS lib_mysqludf_json_info;
DROP FUNCTION IF EXISTS json_array;
DROP FUNCTION IF EXISTS json_members;
DROP FUNCTION IF EXISTS json_object;
DROP FUNCTION IF EXISTS json_values;
#创建
create function lib_mysqludf_json_info returns string soname 'lib_mysqludf_json.so';
create function json_array returns string soname 'lib_mysqludf_json.so';
create function json_members returns string soname 'lib_mysqludf_json.so';
create function json_object returns string soname 'lib_mysqludf_json.so';
create function json_values returns string soname 'lib_mysqludf_json.so';

实例:
1、select json_object(login_name as user,login_password as pwd) as user from t_sys_loginperson;
返回:
{"user":"admin","pwd":"8aff8dd13eeecabe03830865bfa1b2b8"}
{"user":"sch000001","pwd":"e10adc3949ba59abbe56e057f20f883e"}
{"user":"stu000001","pwd":"e10adc3949ba59abbe56e057f20f883e"}

2、select json_array(login_name,login_password) as user from t_sys_loginperson;
返回:
["admin","8aff8dd13eeecabe03830865bfa1b2b8"]
["sch000001","e10adc3949ba59abbe56e057f20f883e"]
["stu000001","e10adc3949ba59abbe56e057f20f883e"]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值