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?


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.

  • 2
    There is no --add-drop-tables flag, it should be --add-drop-table.
    – jojman
    Sep 17 '16 at 10:54

We do use key -B <db-name>, which adds command USE <db-name>;


Did you try adding: --databases THE_DB_NAME


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy