0

I have multiple computers running python applications, each using the same MySQL server. Each of the applications contains a tkinter GUI that allows editing of a set of data (corresponding to data in a table in the MySQL server). Whenever the data is updated one machine (and in turn updated on the MySQL server), I would like the other machines to be prompted to update there displayed data by pulling from the server. I know I could simply have the applications self-update after a given interval, but I would prefer to only update when there is new data to pull.

How should I go about this?

SamBG
  • 270
  • 4
  • 16
  • sounds like you need to dig into MySql Triggers, maybe this answer would help https://stackoverflow.com/questions/17336804/how-to-send-messages-from-server-to-client – kztd Jul 01 '18 at 02:37

2 Answers2

2

This isn't something you can do with MySQL.

There is no provision in the client/server protocol for the server to spontaneously emit messages to a client, so there is no mechanism in MySQL that allows connected clients to be notified of events via a push notification.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Interesting. So just to clarify, there is no place for MySQL triggers as @ktzd commented on the original question? – SamBG Jul 01 '18 at 15:41
  • 1
    Not really. Triggers allow an insert/update/delete to a row in a table to perform an action such as executing another query, but the problem is that the query inside the trigger doesn't get you any closer to notifying other threads. Amazon Aurora (MySQL compatible) allows a trigger to invoke an external Lambda function, which could send notifications via an external system (SNS, SQS, IoT) but then your clients would need to receive such notifications via some other channel (such as subscribing to SNS or listening on an IoT socket), which is certainly possible but significantly more complex. – Michael - sqlbot Jul 01 '18 at 17:34
  • That's very helpful, thanks. I'll probably opt to simply put in a refresh button in place of any automatic polling. – SamBG Jul 01 '18 at 19:34
2

I would suggest that your other client to do a long polling to your database and return a response if there are any feedback.

obl0702
  • 123
  • 11
  • Thanks, this seems like the solution. Do you have any resources I could use to learn how to do this (perhaps specifically with Python connected to MySQL)? I haven't been able to find any. – SamBG Jul 01 '18 at 16:03
  • 1
    There's really no such thing as "long polling" MySQL. If you have a solution, please explain how it's implemented... otherwise, I'd suggest you are proposing something that isn't properly called "long polling" ...perhaps intermittent or periodic polling... which eventually does not scale. – Michael - sqlbot Jul 01 '18 at 17:41
  • Hi SamBG and Michael, sorry if I caused misunderstand here. I means the client (Python) to execute polling periodically (web service or http request) to check if there any record in the database. – obl0702 Jul 02 '18 at 13:01