mysql-udf-http插件的安装与使用 查看原文
安装curl
点击下载地址,下载curl-7.69.0.tar.gz
# 解压curl-7.69.0.tar.gz
tar -zvxf curl-7.69.0.tar.gz
cd curl-7.69.0
# 配置安装路径
./configure -prefix=/usr/local/curl
# 进行安装
make && make install
安装mysql-udf-http
点击下载地址,下载mysql-udf-http-1.0.tar.gz
# 解压mysql-udf-http-1.0.tar.gz
tar -zvxf mysql-udf-http-1.0.tar.gz
cd mysql-udf-http-1.0/
./configure --prefix=/usr/local/mysql --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/lib64/mysql/plugin
# --with-mysql : mysql_config可以通过 find / -name mysql_config进行搜索。有可以没有,没有的话。安装 mysql-devel
# --libdir:是mysql的插件库地址 一般是/usr/lib64/mysql/plugin文件夹
make && make install
安装报错解决方法
- 下载mysql 的源码包,打开源码包文件夹
cd /usr/local/src/mysql-8.0.26
cp -r include/* /usr/local/src/mysql-udf-http-1.0/src
# 再进行编译
make && make install
- 如果还报错
vim mysql-udf-http.c
# 在vim的命令模式下执行以下命令,将my_bool替换为int
:%s/my_bool/int/g
# 再进行编译
make && make install
- 安装成功之后,因为没有找到mysql-udf-http.so导致创建函数失败
# 找到mysql-udf-http.so的位置
find / -name mysql-udf-http.so
cp **/mysql-udf-http.so /usr/local/mysql/lib/plugin/
- 安装的时候报错,找不到libcurl,但是已经安装curl
find / -name pkgconfig
export PKG_CONFIG_PATH=/usr/local/curl/lib/pkgconfig
使用mysql-udf-http
- 创建函数
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';
- 测试
/* 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:[email protected]/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');
- 通过触发器请求
create trigger after_attendance_log after insert on attendance_log for each row
begin
DECLARE REQUEST_URL varchar(200);
select concat('http://jarfly.vaiwan.com/attendance/app/notToken?primaryId=', max(id)) into REQUEST_URL from attendance_log;
SET @tt_re = (select http_get(REQUEST_URL));
end
标签:插件,http,tar,udf,usr,mysql,curl
From: https://www.cnblogs.com/My-Sun-Shine/p/18021239