MySQL - database backup using Linux Command Line

1 points
Created by:

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

Quick solution:

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


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

Practical examples

Example 1:

mysqldump -u root -pEwcrtat318jkD -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 same machine, so we can use host address,
  • we used root account because of allowsed access to any database on server,
  • putting parameters to apostrophes allows us to use any characters.

See also

  1. MySQL - restore database from backup using Linux Command Line
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.