I need to track who changes to a table in mySQL database. Would you please give me an idea how I can determine which of my application users makes changes to a record in a table?
Asked
Active
Viewed 119 times
1
-
1Are you asking how you can determine which *MySQL user* makes changes, or how you can determine which of your *application users* make changes? – eggyal Oct 28 '13 at 18:49
-
1I believe you need to use a Trigger to achieve this. Take a look at a similar question on [SO](http://stackoverflow.com/questions/5547773/how-to-track-changes-in-multiple-columns-in-database-table-for-auditing-purposes) – Chelseawillrecover Oct 28 '13 at 18:50
1 Answers
0
I assume you have a table with 2 columns that their name is colmun1
and column2
You should add modified_by
column and also add this trigger:
DELIMITER |
CREATE TRIGGER before_update_sometable
BEFORE UPDATE ON sometable FOR EACH ROW
BEGIN
IF (NEW.column1 <> OLD.column1 or NEW.column2 <> OLD.column2) THEN
NEW.modified_by = user();
END IF;
END;
|
DELIMITER ;

Arash Mousavi
- 2,110
- 4
- 25
- 47
-
That returns database user. I want the function to return Application users. – Mekuannent Addis Oct 31 '13 at 20:15