The reason many are against the use of triggers really has to do with the lack of control introduced by the need for a second query.
The second query needed for recording information is subjected to the MySQL environment without you having the ability to control storage engine specific aspects.
For example, I once tried to help troubleshoot a MySQL event whose root cause simply boiled down to the storage engine of the table being recorded. From my empirical analysis of that problem, I have sworn off recording audit trail info into InnoDB tables from within a trigger.
I have written earlier posts about the good, the bad, and the ugly of Triggers:
If you must have many triggers, my strong recommendation would be for you to use a combination of the BLACKHOLE storage engine and MySQL Replication.
EXAMPLE
Let's say you have a database that you want to record comments for a user. Have a table called audit_user with the userid of the user and a comments column:
CREATE DATABASE auditinfo;
USE auditinfo
CREATE TABLE audit_user
(
userid INT NOT NULL,
comments INT NOT NULL DEFAULT 1,
PRIMARY KEY (userid)
) ENGINE=BLACKHOLE;
You next setup a trigger that performs this query
INSERT INTO auditinfo.audit_user (userid) VALUES (myuserid)
ON DUPLICATE KEY UPDATE comments = comments + 1;
OK great, but why have the audit_user table use the BLACKHOLE storage engine when nothing is stored in the table? Here is where MySQL Replication comes into play.
Setup a Slave whose sole purpose in life to to catch all auto trail data. Have the Slave replicate from the Master with the replicate-do-db=auditinfo
option. Create the auditinfo database and audit_user table in the Slave as follows:
CREATE DATABASE auditinfo;
USE auditinfo
CREATE TABLE audit_user
(
userid INT NOT NULL,
comments INT NOT NULL DEFAULT 1,
PRIMARY KEY (userid)
) ENGINE=MyISAM;
The binary logs of the Master has the command INSERT INTO auditinfo.audit_user (userid) VALUES (myuserid) ON DUPLICATE KEY UPDATE comments = comments + 1;
recorded. That INSERT is transmitted to the Slave's relay logs. Replication causes that INSERt query to be executed.
So the question remains: What is the benefit of setting this up?
When it comes strictly to recording audit info, the Master does not have any heavy write I/O to slow it down. It simply records the SQL need to do the audit. That SQL is sent over to another machine (the Slave) for actual recording. Naturally, the Master is able to handle a lot more triggers when you setup auditing in this manner. If you do not use this combination of BLACHOLE/MySQL Replication, every query doing an INSERT will slow itself down and seeing hundreds of such queries with unveil significantly poor DB performance.