MySQL saving database to a file and reinserting

Save a database

To save the contents of a database, use
$ mysqldump --databases -u root -p name > name.sql
where name is the name of the database to save the data into, and name.sql is a file which contains the information in the database.

Reinsert the database

To reinsert the data from the above step back into the database, use
$ mysql -u root -p
mysql> source name.sql;
This overwrites any changes in the database which happened after it was saved to name.sql.
Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer