Method of backing up and restoring specified tables with mysqldump

  • 2020-05-06 11:46:40
  • OfStack



mysqldump -u user -p db tab1 tab2 > db.sql  
 

Restore  

mysql -u user -p db < db.sql 
 

Reference:

1. Copy                :       (make sure there are no writes to the database (you can lock the table)) mysqldump        :       mysqldump generates text files
that can be ported to other machines
Example:
Backup the entire database           -->           mysqldump   db1   > /backup/db1.20060725      
Zip backup                           -->           mysqldump   db1   |   gzip   > /backup/db1.20060725
Backup                         -->           mysqldump   db1   tab1   tab2   > /backup/db1_tab1_tab2.sql
Direct remote backup                 -->         mysqladmin   -h   boa.snake.net   create   db1
                                                      -- >           mysqldump   db1   |   mysql   -h   boa.snake.net   db1

Copy the backup table                       -->           cp   tab.*           backup/


Restore
Reload the database with the latest backup files. If you use mysqldump to produce a file, use it as input to mysql. If you copy files directly from the database, copy them directly back to the database directory, however, at this point you need to shut down the database before copying the files, and then restart it.  



Related articles: