HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How to do a mysqldump with a use database in the dump

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
dumpthewithmysqldumpdatabasehowuse

Problem

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?

Solution

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.

Code Snippets

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

Context

StackExchange Database Administrators Q#25199, answer score: 11

Revisions (0)

No revisions yet.