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

So the command I normally use to get a database sent to another server is: mysqldump -u user -p --add-drop-tables database *file*

But I always have to go into the file and add a line at the top: use database;

So that I use the file to import to a different server. Is there a flag in mysqldump to automatically add the use database?

share|improve this question

migrated from stackoverflow.com Oct 1 '12 at 11:27

This question came from our site for professional and enthusiast programmers.

We do use key '-B ', which adds command 'USE ;'

share|improve this answer
up vote 1 down vote accepted

The flag is --databases

mysqldump -u user -p --add-drop-tables --databases database > *file*

So if you have more than one schema names you need to set which databases with the --databases flag. Then it inserts which one is necessary to be used.

share|improve this answer

Did you try adding: --databases THE_DB_NAME

share|improve this answer

Alternatively you can write a small bash script or batch file (depending on OS) with the lines you want to add to the file.

share|improve this answer

Your Answer

 
discard

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