SHOW CREATE TRIGGER – Nope
As of MySQL 5.0 there is no SHOW CREATE TRIGGER which is pretty annoying. I don’t like using “show triggers like
mysqldump -dnt database | sed "/\/\*\!4.*\*\/;*/d" | sed "s_/\*\!5[0-9]*__g" | sed "s_DEFINER=.*\*/__g" | sed "s/\*\/;*//g" | sed "/SET/d" | sed "s/^[ \t]*//" | sed "s/\ \ */ /g" | sed "/--/d"
You will get a dump of ALL the triggers in your database, using this. However, since that’s what I need on this particular example, it’s what I’m sharing. I’m sure I could have cleaned up the code a little and used fewer calls to sed, but frankly I don’t mind, since it works fine.
I hope this helps someone.
4 Responses to SHOW CREATE TRIGGER – Nope
Leave a Reply Cancel reply
Recent Comments
- Anil on MySQL Triggers Tutorial
- Ashish on MySQL Triggers Tutorial
- David on iCal Agenda
- jon on IP address geolocation SQL database
- pim on IP address geolocation SQL database
- jnns on Redis Wildcard Delete
- K.C. Murphy on iCal Agenda
- BA on Experts Exchange should be removed from Google search results
- Andrew on Executing multiple curl requests in parallel with PHP and curl_multi_exec
- Stu on Executing multiple curl requests in parallel with PHP and curl_multi_exec
Recent Posts
- New Project: Jester
- Open New Terminal Tip
- Installing MySQLdb on MacOS Lion
- Headless VM Server Using Ubuntu 11.10
- Get rid of Facebook’s Awful Ticker
- Api Tester now hosted on Github
- Trac .11 jQuery bug
- Multiple Filetypes in Vim
- Git Tip: Setting Up Your Remote Server
- Install issue pymongo on OSX (setuptools out of date)
Categories
- amazon (1)
- answerbag (6)
- apache (9)
- apple (8)
- awk (2)
- bbedit (2)
- c++ (3)
- chrome (2)
- cluster (1)
- cocoa (1)
- collective intelligence (1)
- curl (3)
- db2 (1)
- demand media (1)
- ebay (1)
- eclipse (4)
- erlang (13)
- facebook (1)
- fortran (1)
- gen_server (1)
- git (5)
- google (4)
- haddad (1)
- hdf5 (1)
- html (1)
- innodb (1)
- itunes (1)
- java (2)
- jester (1)
- kvm (1)
- launchbar (1)
- leex (1)
- letsgetnuts.com (1)
- libvirt (1)
- links (6)
- linux (27)
- lucene (1)
- mac (16)
- memcached (1)
- misconception (1)
- mobile (1)
- mono (1)
- mssql (1)
- munin (1)
- mysql (31)
- numpy (1)
- oracle (1)
- php (23)
- puppet (4)
- pyparsing (1)
- pytables (1)
- python (11)
- q&a (1)
- quicksilver (1)
- rant (6)
- readynas (1)
- redis (2)
- regex (1)
- replication (1)
- search (1)
- shitty code (1)
- solr (3)
- spaces (1)
- sshfs (1)
- stored procedure (1)
- svn (5)
- textmate (2)
- tips (22)
- trac (1)
- tutorial (4)
- ubuntu (3)
- Uncategorized (4)
- unix (1)
- vim (3)
- virtual box (6)
- vmware (1)
- weird (3)
- wikipedia (1)
- windows (1)
- xcode (1)








And what about using INFORMATION_SCHEMA?
For example, all the triggers from the server:
mysql> SELECT * FROM TRIGGERS\G
*************************** 1. row ***************************
TRIGGER_CATALOG: NULL
TRIGGER_SCHEMA: control_panel
TRIGGER_NAME: class_test_update
EVENT_MANIPULATION: UPDATE
EVENT_OBJECT_CATALOG: NULL
EVENT_OBJECT_SCHEMA: control_panel
EVENT_OBJECT_TABLE: class_test
ACTION_ORDER: 0
ACTION_CONDITION: NULL
ACTION_STATEMENT: BEGIN
INSERT INTO `historics`.`historic_class_test` ( `id_class_test`, `OLD_varchar_`, `NEW_varchar_`, `OLD_varchar_req`, `NEW_varchar_req`, `OLD_encrypted_`, `NEW_encrypted_`, `user_update`, `ip_update` ) VALUES (OLD.id_class_test, OLD.varchar_, NEW.varchar_, OLD.varchar_req, NEW.varchar_req, OLD.encrypted_, NEW.encrypted_, @REMOTE_USER, @REMOTE_ADDR );
END
ACTION_ORIENTATION: ROW
ACTION_TIMING: AFTER
ACTION_REFERENCE_OLD_TABLE: NULL
ACTION_REFERENCE_NEW_TABLE: NULL
ACTION_REFERENCE_OLD_ROW: OLD
ACTION_REFERENCE_NEW_ROW: NEW
CREATED: NULL
SQL_MODE: NO_FIELD_OPTIONS,MYSQL40,HIGH_NOT_PRECEDENCE
DEFINER: powfull@%
*************************** 2. row ***************************
TRIGGER_CATALOG: NULL
TRIGGER_SCHEMA: control_panel
TRIGGER_NAME: class_test_delete
EVENT_MANIPULATION: DELETE
EVENT_OBJECT_CATALOG: NULL
EVENT_OBJECT_SCHEMA: control_panel
EVENT_OBJECT_TABLE: class_test
ACTION_ORDER: 0
ACTION_CONDITION: NULL
ACTION_STATEMENT: BEGIN
INSERT INTO `historics`.`historic_class_test` ( `type`, `id_class_test`, `OLD_varchar_`, `NEW_varchar_`, `OLD_varchar_req`, `NEW_varchar_req`, `OLD_encrypted_`, `NEW_encrypted_`, `user_update`, `ip_update` ) VALUES ( ‘DELETE’, OLD.id_class_test, OLD.varchar_, NULL, OLD.varchar_req, NULL, OLD.encrypted_, NULL, @REMOTE_USER, @REMOTE_ADDR );
END
ACTION_ORIENTATION: ROW
ACTION_TIMING: AFTER
ACTION_REFERENCE_OLD_TABLE: NULL
ACTION_REFERENCE_NEW_TABLE: NULL
ACTION_REFERENCE_OLD_ROW: OLD
ACTION_REFERENCE_NEW_ROW: NEW
CREATED: NULL
SQL_MODE: NO_FIELD_OPTIONS,MYSQL40,HIGH_NOT_PRECEDENCE
DEFINER: powfull@%
2 rows in set (1.61 sec)
information_schema, is the meta-database, and it supports SQL queries like another database…
Hi Basi,
Selecting from the information schema has the same problems as using show triggers like “table”, in that it doesn’t generate for me SQL that I can modify and easily use to modify the trigger.
I’m lazy, is what it boils down to. Using mysqldump and the script I wrote above, you can easily modify any trigger in your database within seconds. The equivilent of “show create trigger”, except with every trigger.
Hi!
This is a bug. I know about it, and its on our list of things to fix. Yeah, I am sure you are thinking “it looks like a feature request”, but no, it is a bug
Cheers,
-Brian
I cobbled this up for the 5.0 to 5.1.20 crowd. As of 5.1.21, there is a built in SHOW CREATE TRIGGER syntax.
http://forge.mysql.com/snippets/view.php?id=103