Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
add comment

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

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

4 Answers

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

share|improve this answer
add comment

Did you try adding: --databases THE_DB_NAME

share|improve this answer
add comment

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
add comment
up vote 0 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
add comment

Your Answer

 
discard

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