I normally do not separate triggers from the tables they were meant for. I dump like this:
mysqldump -u... -p... --no-data --routines --triggers dbname > DBSchema.sql
Check for presence of routines and triggers like this:
SELECT COUNT(1) FROM mysql.proc;
SELECT COUNT(1) FROM information_schema.triggers;
SELECT * FROM information_schema.triggers\G
If you want to get this done to all DBs in the MySQL Instance, do this:
mysql -u... -p... -A -N -e"SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','mysql')" > /tmp/dblist.txt
for DB in `cat /tmp/dblist.txt`
do
mysqldump -u... -p... --no-data --no-create-info --routines dbname > ${DB}-routines.sql
mysqldump -u... -p... --no-data --triggers dbname > ${DB}-schema-triggers.sql
done
That way, stored procedures go in a routines dump for the DB, while the schema and triggers go in another dump.
grep 'CREATE TRIGGER'– Derek Downey Oct 02 '11 at 18:44--triggersdumped by default? What would be the difference between--no-data --routines --triggersvs--no-data --routines? – Pacerier May 07 '15 at 14:05--skip-triggerson such occasions (such as setting up slaves that didn't need the triggers). As a constant reminder to myself of the possibility of skipping options, I always use certain flags in mysqldumps (--routines,--triggers) even if they are default. So, it's just a personal preference. If you trust that a default setting will remain a default from version to version and never deal with adhoc situations, then you express the mysqldumps as needed as long as the resulting mysqldump is correct for you. – RolandoMySQLDBA May 07 '15 at 14:21With this: DROP TRIGGER /!50032 IF EXISTS /
– AlexandruSerban Nov 13 '15 at 09:38$2;;\n$1