Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to create a trigger in mysql without hardcoding the database name?

Doing a typical create trigger will stop working if I dump the database and then import it into a database of a different name.

share|improve this question

migrated from Dec 10 '13 at 20:54

This question came from our site for system and network administrators.

I guess I'll guess an answer to my question. A lot of mysql documentation just references a table name without specifying a database, so I am assuming the database is optional and if you don't include it, mysql will use the current one.

share|improve this answer
This is the default behavior on most database systems I've encountered: "If the database name / schema namespace is not specified, assume the current one." – voretaq7 Dec 10 '13 at 22:31

If you mysqldump a table with

mysqldump --triggers ...

the code for the trigger definition is included.

However, there is a hardcoding situation you want to be cognizant of



  insert into outsidedb.audir_trail values (...);

END $$


If you mysqldump mytable and import it into another DB Server, the trigger works only if and only if the database outsidedb exists on the new DB Server and has the table called audit_trail.

Therefore, please keep aware of all hardcoding situations inside and outside of your triggers.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.