EN
MySQL - database schema backup using Linux Command Line (without data)
25
points
In this short article, we would like to show how to make only MySQL database schema backup using Linux Terminal (command line).
Quick solution:
mysqldump -d -u db_username -pdb_password -h db_hostname db_name > /path/to/backup.sql
Where: -d
is shortcut of --no-data
.
Notes:
- do not use space beetween
-p
anddb_password
,-h db_hostname
is optional (lack meanslocalhost
connection),-d
or--no-data
disable data backup (only schema is backuped).
Practical examples
Example 1:
mysqldump -d -u root -pSecretPassword -h 127.0.0.1 gallery > ./2020_09_12_17_21_gallery.sql
Example 2:
/usr/bin/mysqldump -d -u 'root' -p'SecretPa$$word' -h '127.0.0.1' 'gallery' > '/path/to/backup/db/2020_09_12_17_21_gallery.sql'
Where:
- MySQL server is installed on the same machine, so we can use
127.0.0.1
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.