Hi I was wondering if there was a way in MySQL to automatically send an e-mail to myself whenever there is a row added to a MySQL table?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
You can get the
lastInsertedId
and if it's not zero send e-mail.The best way to achieve this would be using a trigger and a cron. Create a 'notification queue' table and populate that with a trigger when a row is inserted in the desired table.
eg.
Then define a simple trigger:
From that point, all you need to do is make a crontab run on the server (say every minute) which selects from the
notification
table wheresent = 0
, send the notification and setsent = 1
As far as I know, that's the best way to get that information out of the DB without reading the bin logs.
If you need an example of the script to run with cron: