This can be done with mysqldump function. See the below examples:
For a single whole DB
$ mysqldump -u [uname] -p db_name > db_backup.sql
For able within a DB
$ mysqldump -u [uname] -p db_name table1 table2 > table_backup.sql
To auto-compress the output, use gzip:
$ mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
To do it remotely and you have the server access
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p db_name > db_backup.sql
It should drop the .sql file in the folder you run the command-line from.
EDIT: Updated to avoid inclusion of passwords in CLI commands, use the -p option without the password. It will prompt you for it and not record it.
Interested in Linux? Check out this Linux Certification by Intellipaat.