Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
330 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
ID: 34994468
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
ID: 34999289
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 2000 total points
ID: 35017935
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 2000 total points
ID: 35018169
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
ID: 35690914
Both solutions worked.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

916 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