环境
CentOS Linux release 7.8.2003 (Core)
mysql Ver 15.1 Distrib 5.5.65-MariaDB, for Linux (x86_64) using readline 5.1
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 ../
注意:/usr/bin 是自己的mysql 安装目录 如果没有mysql_config文件的话得先安装devel
yum install -y mysql-devel
如果不知道自己的mysql安装目录的话就
which mysql
还需要安装一些编译的包要不然会碰到下面的问题
yum install -y libstdc++.i686 zlib.i686 glibc.i686 gcc-c++
yum install gcc gcc-c++ autoconf automake
有可能还会遇到下面的问题
configure: error: Package requirements [libcurl >= 7.15.5] were not met: No package 'libcurl' found
首先使用 yum search libcurl 查找 libcurl 库
需要下载一下工具包
yum install -y libcurl-devel.x86_64
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/bin --with-mysql=/usr/bin/mysql_config
make && make install
cd ../
然后进入数据库
create function http_get returns string soname 'mysql-udf-http.so'; (这个命令可能会出错,因为我形成的.so文件不再对应目录下)
上图所示是成功时候的 我的一开始会错误 会报mysql-udf-http.so不再对应目录下 然后你就可以找一下
find / -name mysql-udf-http.so 找到后创建一个软连接
ln -s /usr/bin/lib/mysql-udf-http.so(这是我找到的位置) /usr/lib64/mysql/plugin/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';
测试
我输入的是百度的网址 下面是测试结果
删除mysql-udf-http UDF函数
drop function http_get;
drop function http_post;
drop function http_put;
drop function http_delete;
本文也借鉴与http://blog.zyan.cc/mysql-udf-http/ 但是后来环境问题出现偏差 又搞了好长时间环境