Solved

How do I write updates from a table to a text log file in MySQL 5.5 after an insert or update?

Posted on 2011-02-27
5
323 Views
Last Modified: 2012-06-27
I was wondering if anyone had a solution on how to set up a process for writing a new row to a text file once a table has been updated in MySQL 5.5?

I've researched using mysqldump, but I don't think this can be called within MySQL?

Looking at a second option, the  INTO OUTFILE can't overwrite existing files.

Basically I have a table and as it is updated, I would like to log a subset of the information in that table to a text log file. The text file should be updated immediately once the insert or update has happened. Preferrably the new row would be concatenated to the existing text file....

Any ideas would be greatly appreciated.

Jake
0
Comment
Question by:seedcoit
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:AnilKumarSharma
Comment Utility
Before MySQL 5.0.10, triggers cannot contain direct references to tables by name. Beginning with MySQL 5.0.10, you can write triggers.
Check out this..
http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

For sample check this forum thread (and follow it for more info),

http://forums.mysql.com/read.php?99,68167,68333#msg-68333
0
 

Author Comment

by:seedcoit
Comment Utility
I created a trigger, but I don't think it can call mysqldump from there.

And as I mentioned earlier, the INTO OUTFILE statement can't overwrite existing text files. I need just one text file, updated after every insert or update.
 

0
 
LVL 1

Accepted Solution

by:
RealRaven earned 500 total points
Comment Utility
The key here is the text file.

I see two options. Either log to a table and then dump i manually (or with cron) every now and then

or

Write a custom UDF to do this, there is a couple here http://www.mysqludf.org/lib_mysqludf_sys/index.php that might work, I haven't tried them myself. A call to there sys_exec inside the trigger would do the job.

0
 
LVL 1

Assisted Solution

by:RealRaven
RealRaven earned 500 total points
Comment Utility
I just thought of another solution. I don't know if it fits you or not but it's worth a try

There is an engine called CVS that keeps all information in comma separated list on disk. The file is located next to the .frm file and is called .CVS

I guess it has some performance issues but depending on your application it might work.

Put a trigger on the original table that puts a row in the table with the CVS-engine and then just read the CVS-file.
0
 

Author Closing Comment

by:seedcoit
Comment Utility
Both solutions worked.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now