I have a python code to be executed when a database table is updated. How can I write a Mariadb trigger for the same?
1 Answer
By default MariaDB doesn't support execution of external programs.
As a workaround you can call a udf (user defined function) which executes python interpreter. lib_mysqludf_sys from UDF Repository for MySQL might be the right udf for.
So your trigger definition might look like
CREATE TRIGGER my_trigger BEFORE UPDATE ON my_tbl
....
SET RC= sys_exec('/usr/bin/python my_script.py');
....
5 Comments
Phoenix
Have tried it. I am cyurrently using Fedora24. Unable to install mysqludf here.
Phoenix
The error I get is "You need libmysqlclient development software installed". However, I am using mariadb. So the corresponding package is mariadb-devel, which is already installed.
Georg Richter
git clone github.com/mysqludf/lib_mysqludf_sys - the shared object in this repo doesn't depend on libmysqlclient.
Phoenix
I used the same repo. In the install.sh file, the code is as follows:
Phoenix
if test $? -ne 0; then echo "ERROR: You need libmysqlclient development software installed " echo "to be able to compile this UDF, on Debian/Ubuntu just run:" echo "apt-get install libmysqlclient15-dev" exit 1