1)Below is the script example to backup mysql database in command line:-

$ mysqldump -h localhost -u username -p database_name > backup_db.sql

2)If your mysql database is very big, you might want to compress your sql file.
Just use the mysql backup command below and pipe the output to gzip,
then you will get the output as gzip file.

$ mysqldump -u username -h localhost -p database_name | gzip -9 > backup_db.sql.gz

3)If you want to extract the .gz file, use the command below:-

$ gunzip backup_db.sql.gz