snippetsqlModerate
How to do a mysqldump with a use database in the dump
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?
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
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.
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.