How can I restore a backup of a MySQL database?

Posted on in Categories , , , , last updated May 3, 2008

Q. I made MySQL backup using mysqldump -u user -h localhost -ppassword forumdb | -gzip -9 > forumdb.sql.gz command. How do I restore MySQL database backup using a shell prompt under Linux / UNIX operating system?

A. mysqldump command is text-based client or tool for dumping or backing up mysql databases, tables and or data. You can use same command as follows:
$ gunzip forumdb.gz
Now, restore using mysqldump:
$ mysqldump -u user -h localhost -ppassword forumdb < forumdb.sql
Alternatively, use mysql command as follows:
$ mysql -u user -h localhost -ppassword forumdb < forumdb.sql

See also:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

Leave a Comment