简体   繁体   中英

Clean, low-overhead way to send an email when a mysql/mariadb table is updated?

I need to send an email when a record is added to a table.

A bunch of googling has left me with the impression that the only choices are "bad" and "really bad" and was wondering if anybody had any clean, solid, reliable suggestions.

So far I've found:

  • Use a mysql plugin that sends the mail. I'd rather not do this because I have a perfectly good mail server and the database wasn't designed to send mail.

  • Poll the table periodically from an external program, look for changes and send the mail if appropriate. This is almost OK, but I'd rather skip the dead time between the record being added and the next poll.

I had considered using SELECT ... OUTFILE, however this is really limited because it won't overwrite the output file and the only way to change the filename is by building the query with dynamic SQL, which can't be used inside a trigger.

I could write a socket listener and have Mysql open the socket and tell the mail app there are records waiting, however there doesn't seem to be a way to open a socket from mysql.

It feels like I must be missing something here.

All I want is to run an external application when a record is added.

Has anybody run into a clean, low overhead way to do this?

Modify the code that is adding the record and have it do the notifications. If you put it in a try/catch block you will know for sure whether or not the record was added successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM