Skip to main content

Backup and Restore Database SSH

in this wiki we have  Backing up and restoring  Database from local server and external server,

Backup Database

Backup from local server

mysqldump -u{username} -p{passoword} {database} | gzip > {path}/backup_filename_$(date +%F).sql.gz

Backup from external server

mysqldump -P {port} -h {host} -u{username} -p{passoword} {database} | gzip > {path}/backup_file_name_$(date +%F).sql.gz

Backup specific tables

mysqldump -u{username} -p{passoword} {database} table1 table2 > {path}/table1_table2.sql

 

Backup Paramters

- backup without table create, you can use this parameter  " --no-create-info "

mysqldump -u{username} -p{passoword} {database} table1 table2  --no-create-info > {path}/table1_table2.sql

 

Unzip the sql gz file

gunzip < filename.sql.gz filename.sql.gz.sql

Restore Database

Restore Database to Local Sever

mysql -u{username} -p{password} {database}< {path}/backup_filename.sql

Restore Database to External Sever

mysql -h{host} -P {port} -u{username} -p{password} {datbase} < {path}/filename.sql

Note

Replace {username},{password},{database},{path},{host},{Port} : with your information