MySQL - database backup using Linux Command Line

19 points
Created by:

In this short article, we would like to show how to make MySQL database backup using Linux Terminal (command line).

Quick solution:

mysqldump -u db_username -pdb_password db_name > /path/to/backup.sql


mysqldump -u db_username -pdb_password -h db_hostname db_name > /path/to/backup.sql



  • do not use space beetween -p and db_password,
  • -h db_hostname is optional (lack means localhost connection).


Practical examples

Example 1:

mysqldump -u root -pSecretPassword -h gallery > ./2020_09_12_17_21_gallery.sql

Example 2:

/usr/bin/mysqldump -u 'root' -p'SecretPa$$word' -h '' 'gallery' > '/path/to/backup/db/2020_09_12_17_21_gallery.sql'


  • MySQL server is installed on the same machine, so we can use host address,
  • we used root account that has access to any database on the server,
  • putting parameters to apostrophes allows us to use any characters.


See also

  1. MySQL - restore database from backup using Linux Command Line
  2. MySQL - database schema backup using Linux Command Line (without data)

Alternative titles

  1. MySQL - database dump using Linux Command Line
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MySQL - Problems

MySQL - database backup using Linux Command Line
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

â€ïžđŸ’» 🙂