How to back up and restore MySQL database

To backup a mysql database to a file use the following syntax:
mysqldump -u[username] -p[password] nameofdatabase > nameofdatabase.sql
To restore from the backup use the following method:
mysql -u root -p
password: <type password> <enter>
> create database <nameofdatabase>; <enter>
> grant all on nameofdatabase.* to nameofuser@localhost identified by ‘nameofuserpassword’;
> flush privileges;
> exit;
mysql -u root -p nameofdatabase < nameofdatabase.sql
password: <type password> <enter>

Leave a Reply

Your email address will not be published. Required fields are marked *