Backup

Backup all databases

mysqldump -u root -p[root_password] --all-databases > /tmp/all-database.sql

Backup a single database

mysqldump -u root -p[root_password] [database_name] > /tmp/dumpfilename.sql

Backup a single database and compressed it to a .gz

mysqldump -u root -p [root_password] [database_name] | gzip -9 > /tmp/dumpfilename-$(date +%d-%m-%Y).sql.gz

Backup multiple databases

mysqldump -u root -p[root_password] --databases [database_name_1] [database_name_2] > /tmp/dumpfilename.sql

Verify the dumpfilename.sql dump file contains both the database backup.

grep -i "Current database:" /tmp/dumpfilename.sql

Backup a specific table

mysqldump -u root -p[root_password] [database_name] [table_name] > /tmp/dumpfilename_with_specific_table.sql

Restore

mysql -u root -p[root_password] [database_name] < dumpfilename.sql

To restore compressed backup files:

gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]