In one of my previous blog posts I showed you the difference
between the functions CURRENT_USER()
and
SESSION_USER()
and promised to show you how to use
them for auditing with triggers and what you have to watch out
for when updating to MySQL 5.0.17. With this release now being
just a few hours old, let's finally do that and set up a log that
stores all the changes your users apply to a given table.
I'll use a pretty simple base table for the purpose of this
article and will set up all the tables and triggers as user
root@localhost
.
CREATE TABLE t (
t_id INT PRIMARY KEY AUTO_INCREMENT,
v VARCHAR(32)
);
Now we need to create the table for auditing. In addition to all
the columns from the base table it will usually contain
additional columns for a time stamp, the operation performed on
the base table …
[Read more]