I have a BEFORE UPDATE trigger on one table. Now in that trigger, I want to identify whether the update query is sent from application (Java) or it is direct from database access, like a query from MySql command prompt.
Is it possible in MySql trigger ?
No. Triggers are fired independent of clients. They are not built for client specific concerns.
And hence you can't find which client's statement caused the trigger to fire.
Related
I'm currently writing my Main Assignment on my last semester at my study (IT-Engineering with Networking) and currently working with MySQL.
My question is: Is it possible to execute a Shell script/Command from within a MySQL Trigger/Procedure? Or can it be done from a CASE statement?
I've been searching around the internet and read that it's inadvisable to do it.
But I need a script to check a table in a database for alerts and then warn people if there is any.
If there is anyway else this could be done, then I'm open for ideas.
Any input will be appreciated :)
You can read this blog for triggering a shell script from MySQL:
https://patternbuffer.wordpress.com/2012/09/14/triggering-shell-script-from-mysql/. To summarize, two options are presented:
Polling. To improve performance, a trigger could record the change in another table which you poll instead.
MySQL UDF. Write your own plugin, and beware of security implications!
I think for your requirement just write a python/php/perl script which will connect your MySQL DB and query the alert table for any alert and accordingly show warning message on the screen or send email/sms warning.
I want the application to be notified when the database is changed.
I can't use trigger. Because we know the DB's connection message, but we can't modify the db.
So can anyway make application be notified by a connection, like oracle JDBC's Database Change Notification.
So can anyway make application be notified by a connection?
No.
There is a user-defined extension you could use, if you control your MySQL server, to send messages (amqp) from MySQL. You can use that extension in a trigger. https://github.com/mysqludf/lib_mysqludf_stomp#readme
Otherwise, you are out of luck on this. You need to add this notification functionality to the code you use to INSERT and UPDATE rows in your table.
I'm currently writing my Main Assignment on my last semester at my study (IT-Engineering with Networking) and currently working with MySQL.
My question is: Is it possible to execute a Shell script/Command from within a MySQL Trigger/Procedure? Or can it be done from a CASE statement?
I've been searching around the internet and read that it's inadvisable to do it.
But I need a script to check a table in a database for alerts and then warn people if there is any.
If there is anyway else this could be done, then I'm open for ideas.
Any input will be appreciated :)
You can read this blog for triggering a shell script from MySQL:
https://patternbuffer.wordpress.com/2012/09/14/triggering-shell-script-from-mysql/. To summarize, two options are presented:
Polling. To improve performance, a trigger could record the change in another table which you poll instead.
MySQL UDF. Write your own plugin, and beware of security implications!
I think for your requirement just write a python/php/perl script which will connect your MySQL DB and query the alert table for any alert and accordingly show warning message on the screen or send email/sms warning.
I have a systemEvents table.
Trigger will be running, so whenever a new row is added, it should fetch the details from the systemEvents table and send a details to the SNMP manager as a SNMP trap/inform.
For one of your own tables, you can add functions to MySQL through its user-defined function (UDF) interface. This SO answer shows how to invoke PHP scripts through MySQL triggers (though similar should be ok for any scripts eg net-snmp ones to send traps).
EDIT: However after seeing comments from #Joddy, I realise now that it is probably the built in systemEvents table you want, i.e. it is state of whole MySQL you want, so one of tools he mentions may be simpler than UDF approach.
Ques: I have two database one is client's database(live database) and another is mine.I am using MySQL database. I should not access client's database directly so I created my own database. By using 'Talend' data warehousing tool I created job for each table and by executing all jobs I can get all updated data from client's database(live database) to my database. I need to execute these jobs manually for getting updated data into my Database, But my question is: is there any process which will automatically remind me, when client insert or update data on there data base so I can execute those jobs manually to get updated data into my database ?? or if client update their any database table so automatically associated job will Execute/Run ?? Please help me on this.
You would need to set up a database trigger that somehow notifies the Talend job and runs it. To do this you'd typically call the job as a web service using a stored procedure or user defined function. This link shows a typical way that a web service may be called on an update trigger for example.
If your source data tables are large, rather than extracting all of the data from the table and then I guess dropping your table and recreating you could use a tMysqlCDC component to only affect changes. The built in tutorial for the component looks like it pretty much covers a useful example of this in practice. If you are seeing regular changes in the source database this could make your job much more performant.
If you have absolutely no access to your client's database then you could alternatively just run the job with some scheduler. The Enterprise versions of Talend come with the Talend Administration Console that allows you to set CRON triggers for a job and could easily be set to run every minute or any other interval (not seconds). Alternatively you could use your operating systems scheduling system to run the job at your desired intervals.
If you can't modify your clients database (i.e. add triggers), and there is no other way to identify changed records (i.e. some kind of audit table) then you're our of luck.