MySQL backup and restore
Backing up your database is important, here's some useful information to help you backup your data within the MySQL environment.
mysqldump -uUsername -p dbname > dbname.sql
That will backup your database as dbname.sql and put that file in your current directory. Mysqldump has many useful options you can use. for example, if we used -c , the dump would "Use complete Insert Statements" vs. "Incomplete" ones. See below resources for more information on options.It's worth mentioning that the mysqldump command is not required to dump a database, using mysql works just fine too, just doesn't have all the dump options. Replacing mysqldump with mysql in the above example will work but options such as -c will not work.
To also compress your dump, to take less space, you could also include gzip in your command line, such as :
mysqldump -uUsername -p dbname | gzip > dbname.gz
To import the database into a blank mysql database, do the following :
mysql -uUsername -p dbname < dbname.sql
Or if you're importing a gzipped archive then you'll do the following :
gunzip < dbname.gz | mysql -uUsername -p dbname