1

I am having trouble finding this answer anywhere on the internet. I want to be able to monitor a row in a MySQL table for changes and when this occurs, run a Python function. This Python function I want to run has nothing to do with MySQL; it just enables a pin on a Raspberry Pi. I have tried looking into SQLAlchemy; however, I can't tell if it is a trigger or a data mapping. Is something like this even possible?

Thanks in advance!

Ryan F
  • 175
  • 3
  • 14
  • Why not use `pull` instead of `push`? if this is a specific row, just query it for changes every X minutes/seconds. If these could be many rows, create a `flag` table and add `UPDATE` triggers to alter the flag there, and your python application will `poll` for changes and set the flag back... – van Apr 09 '13 at 20:02

2 Answers2

4

What about a cron job instead of create a loop? I think it's a bit nicer.

Omar
  • 689
  • 3
  • 16
3

make a loop which keeps checking the value of that row in MySQL table,the moment the value changes, call the function you want to execute. you can also refer to python: how to get notifications for mysql database changes?

Community
  • 1
  • 1
scottydelta
  • 1,786
  • 4
  • 19
  • 39
  • It sounds like UDF is the only way to do it. I just don't really want to make a loop because it seems like it could really burden the database with overhead. I was hoping to make it check more intelligently. My inspiration is kinda like Dropbox. It only syncs when it gets changes. – Ryan F Apr 09 '13 at 13:59
  • 2
    If all you are doing is `select my_column from my_table where ...` you're not really burdening the DB – Brad Apr 09 '13 at 14:04
  • Really? If that is true, this is a simple solution. – Ryan F Apr 09 '13 at 14:13
  • 1
    user2112825 is right, because MySQL has been designed to handle a large number of operations simultaneously, this would hardly affect the functioning of your database. – scottydelta Apr 09 '13 at 15:53