Languages
[Edit]
EN

MySQL - restore database from backup using Linux Command Line

5 points
Created by:
Root-ssh
76510

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

Quick solution:

cat /path/to/backup.sql | mysql -u db_username -pdb_password -h db_hostname db_name

Notes:

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

Practical examples

Example 1:

cat ./2020_09_12_17_21_gallery.sql | mysql -u root -pEwcrtat318jkD -h 127.0.0.1 gallery

Example 2:

cat "/path/to/backup/db/2020_09_12_17:21_gallery.sql" | mysql -u "root" -p"SecretPa$$word" -h "127.0.0.1" "gallery"

Secure command example

Calling command with password as parameter is not save because is visible as process and stays in command history.

We can type password in program with:

cat /path/to/backup.sql | mysql -u db_username --password db_name

See also

  1. MySQL - database backup from Linux Command Line
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join