0

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 1

3

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');
  ....
Sign up to request clarification or add additional context in comments.

5 Comments

Have tried it. I am cyurrently using Fedora24. Unable to install mysqludf here.
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.
git clone github.com/mysqludf/lib_mysqludf_sys - the shared object in this repo doesn't depend on libmysqlclient.
I used the same repo. In the install.sh file, the code is as follows:
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.