What are MySQL triggers and how to use them?AA-00326The MySQL trigger is a database object that is associated with a table. It will be activated when a defined action is executed for the table. The trigger can be executed when you run one of the following MySQL statements on the table: INSERT, UPDATE and DELETE. It can be invoked before or after the event. Triggers are available in MySQL 5.0.2 and later. You can find detailed explanation of the trigger functionality including its syntax in the following article: http://dev.mysql.com/doc/refman/5.0/en/triggers.html However, the setup of a MySQL trigger requires the MySQL SUPERUSER privileges. On the servers offered by us, such privileges can be granted only on dedicated or vps servers. Granting SUPERUSER privileges to a user hosted on a shared server is a security issue and this is why we don’t do it. The alternative solution is to manipulate the data inserted using the above MySQL statements through a suitable php code in your scripts. Here is an example of a MySQL trigger:
mysql> CREATE TABLE people (age INT, name varchar(150));
mysql> delimiter //
mysql> INSERT INTO people VALUES (-20, ‘Sid’), (30, ‘Josh’);
mysql> SELECT * FROM people; |