mysql_udf_http(根据mysql表自动触发发送http请求)

下载 tar包
wget http://mysql-udf-http.googlecode.com/files/mysql-udf-http-1.0.tar.gz
解压
tar -vzxf mysql-udf-http-1.0.tar.gz
cd mysql-udf-http-1.0
编译
./configure --prefix=/usr/local/mysql --with-mysql=/etc/my.cnf
make && make install
注释 如果报错 说明 缺少mysql源码文件
下载mysql 的源码包
打开源码包文件夹
cd /usr/local/src/mysql-8.0.16
cp -r include/* /usr/local/src/mysql-udf-http-1.0/src
再进行编译 make && make install
如果还报错则
vim mysql-udf-http.c
在命令行模式
:%s/my_bool/int/g
这样再进行make && make install
然后
cp -r /usr/local/mysql/lib/mysql-udf-http.so /usr/lib64/mysql/plugin/


打开mysql client端进行测试
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://127.0.0.1:5000/"); # 访问 flask 服务
如果查出东西来就证明成功了。

创建表测试
CREATE TABLE IF NOT EXISTS `test`(
`id` INT UNSIGNED AUTO_INCREMENT,
`k` VARCHAR(100) NOT NULL,
`v` VARCHAR(40) NOT NULL,
PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

创建触发器测试
DELIMITER |
DROP TRIGGER IF EXISTS test_update;
CREATE TRIGGER test_update
AFTER UPDATE ON test
FOR EACH ROW BEGIN
SET @tt_resu = (SELECT http_get('http://127.0.0.1:5000/?update=true'))
END |
DELIMITER ;

更新表触发
update test set v='c' where id =1

posted @ 2019-05-31 17:08  Weibull  阅读(2160)  评论(0编辑  收藏  举报