Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL listen notify equivalent

Is there an equivalent of PostgresQL's notify and listen in MySQL? Basically, I need to listen to triggers in my Java application server.

like image 988
smk Avatar asked Apr 12 '14 14:04

smk


People also ask

What is Wait_timeout in mysql?

wait_timeout : The number of seconds the server waits for activity on a noninteractive connection before closing it. connect_timeout : The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake.

How do I set system variables in mysql?

System variables can be set at server startup using options on the command line or in an option file. Most of them can be changed dynamically while the server is running by means of the SET statement, which enables you to modify operation of the server without having to stop and restart it.

What triggers mysql?

A trigger is a named database object that is associated with a table, and that activates when a particular event occurs for the table. Some uses for triggers are to perform checks of values to be inserted into a table or to perform calculations on values involved in an update.


2 Answers

Ok, so what I found is that you can make UDF functions in mysql that can do anything but need to be written in C/C++. They can be then called from triggers on updates in database and notify your application when update happened. I saw that there are some security concerns. I did not use it myself but from what I can see it looks like something that could accomplish what you want to do and more.

http://dev.mysql.com/doc/refman/5.6/en/adding-udf.html

like image 103
Tomasz Avatar answered Oct 11 '22 02:10

Tomasz


The github project mysql-notification provides a MySQL user defined function MySQLNotification() as a plugin to MySQL that will send notification events via a socket interface. This project includes a sample NodeJS test server that receives the notification events that could be adapted for Java or any other socket service.

Example use:

$ DELIMITER @@ $ CREATE TRIGGER <triggerName> AFTER INSERT ON <table>    FOR EACH ROW    BEGIN       SELECT MySQLNotification(NEW.id, 2) INTO @x;    END@@ 

Project includes full source code and installation instructions for OSX and Linux. License is GNU v3.

like image 44
Tony O'Hagan Avatar answered Oct 11 '22 03:10

Tony O'Hagan