下載 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