I have successfully dumped an entire MySQL database using
mysqldump --databases
generating a nice .txt file. However, I can't see how to read the whole file back into MySQL in one go; mysqlimport seems to want just one table at a time.
When you've generated some file (say db-dump.sql
) with mysqldump
, you can import it to your other database with the mysql
command :
mysql --user=XXX --password=XXX --host=YOUR_HOST DATABASE_NAME < db-dump.sql
And, if you don't want the password to appear in a command, you can use :
mysql --user=XXX -p --host=YOUR_HOST DATABASE_NAME < db-dump.sql
As a sidenote, if you want to copy one DB to another one, you don't need to use a file, and can just directly pipe the output of mysqldump
to mysql
:
mysqldump --user=XXX --password=XXX --host=SOURCE_HOST SOURCE_DB | mysql --user=XXX --password=XXX --host=DESTINATION_HOST DESTINATION_DB
(It should even be faster, as you're not using a temporary file that resides on disk)