MySQL or MariaDB UDF(User-Defined Functions) HTTP Client Plugin
Call RESTful API on query.
- Clone Source
git clone https://github.com/RebirthLee/mysql_udf_http_golang.git udf cd udf- Auto Build
bash ./install.sh {username} {password}{username} replace your MySQL or MariaDB Username.
{password} replace your MySQL or MariaDB Password(Optional).
- Manual Build
bash ./build.shBuild output is http.so, move file to plugin_dir path.
if you don't know plugin_dir path.
Command input this on MySQL, MariaDB connection.
SHOW VARIABLES LIKE 'plugin_dir'; Ex)
$ mysql -u root -p Enter password: And
MariaDB [(none)]> SHOW VARIABLES LIKE 'plugin_dir'; +---------------+-----------------------------------------------+ | Variable_name | Value | +---------------+-----------------------------------------------+ | plugin_dir | /usr/local/Cellar/mariadb/10.3.12/lib/plugin/ | +---------------+-----------------------------------------------+ 1 row in set (0.001 sec)and http.so move to Value path.
mv ./http.so /usr/local/Cellar/mariadb/10.3.12/lib/plugin/- HTTP HELP
CREATE FUNCTION http_help RETURNS STRING SONAME 'http.so';- HTTP GET
CREATE FUNCTION http_get RETURNS STRING SONAME 'http.so';- HTTP POST
CREATE FUNCTION http_post RETURNS STRING SONAME 'http.so';SELECT http_help();- Prototype
SELECT http_get(url, option...);- Simple Request
SELECT http_get('http://example.com');Return
{ "Body": String(HTML) }-
Output Option
-O outputTypeDefine kind of result. -
Kinds
PROTO,STATUSorSTATUS_CODE,HEADER,BODY(default),FULL
-O PROTO|STATUS|HEADER|BODYsame this-O FULL.
SELECT http_get('http://example.com', '-O FULL');Return
{ "Proto": String(Http Version, HTTP/1.0, HTTP/1.1, HTTP/2.0), "Status": String(Status Code, 200 OK, 404 NOT FOUND), "Header": JSON(`{Key : Array, ...}`), "Body": String(HTML, Base64, Hexdecimal) }SELECT http_post();