mysql console backup restore

Question: How to backup the whole database?

Answer: Just omit the “table_name” argument. For example, mysqldump -u root -pwordpress > D:\wordpress.sql

Question: How to backup all the databases in MySQL?

USE –force to continue on errors

Answer: Use “–all-databases”. For example, mysqldump -u root -p –all-databases > D:\db.sql

linux mysqldump -u admin -p –all-databases > db.sql

Restoring

Now let’s to restore it. Enter the following command in the command line window (or shell):

mysql -u root -p wordpress < D:\wordpress_posts.sql

This will restore the “wp_posts” table. You need to specify the database name. Here, it is “wordpress“. The following command restore the whole database:

mysql -u root -p wordpress < D:\wordpress.sql

If you want to restore all the databases (you used “–all-databases” argument to generate a backup file before), you don’t need to specify the database name.

mysql -u root -p < D:\db.sql

Leave a comment