Is it possible to call a web url from mysql trigger?
for开发者_如何学Go example: I created a trigger for on insert. At that time, I want call a web url like http://www.example.com/.
Not directly -- you have to create a user-defined function and hook it in.
P.S.: This sounds like a terrible way to use a database.
I hope that this article will be useful for you
source: http://vorachet.blogspot.com/2013/03/how-to-install-mysql-udf-on-centos.html
How to install MySQL UDF on CENTOS
How to install MySQL UDF on CENTOS
Step1. Download the MYSQL UDF at https://github.com/mysqludf/lib_mysqludf_sys
Step2. Run make script
The default make file written by the project owner at step1 does not works for CentOS 64bit
We need a bit customization as follow.
gcc -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so -fPIC
Precondition: Make sure you have MySQL header files. You can prepare the header files using this command.
yum install mysql-devel.x86_64
Step3. Configure plugin dir in /etc/my.cnf
...
[mysqld]
plugin_dir=/var/lib/mysql/plugin
...
NOTES: Do not forget to change directory owner to mysql
chown mysql: mysql -R /var/lib/mysql/plugin
Step4. Copy library to plugin dir
cp /usr/lib/lib_mysqludf_sys.so /var/lib/mysql/plugin
Step5. Restart MYSQL and Execute this SQL statements
DROP FUNCTION IF EXISTS lib_mysqludf_sys_info;
DROP FUNCTION IF EXISTS sys_get;
DROP FUNCTION IF EXISTS sys_set;
DROP FUNCTION IF EXISTS sys_exec;
DROP FUNCTION IF EXISTS sys_eval;
CREATE FUNCTION lib_mysqludf_sys_info RETURNS string SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_get RETURNS string SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_set RETURNS int SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.so'
TESTING: SELECT sys_exec ('touch /var/lib/mysql/test.txt ')
You should see /var/lib/mysql/test.txt after above statement is executed.
精彩评论