Home >Database >Mysql Tutorial >How Do I Backup and Restore a Single MySQL Table?
Backup and Restore of a Single MySQL Table
By default, the mysqldump utility backs up the entire database. However, it may be necessary to selectively backup a single table.
How to Backup a Single Table:
Exporting the table data to an .sql file:
mysqldump db_name table_name > table_name.sql
Exporting from a remote database:
mysqldump -u db_username -h db_host -p db_name table_name > table_name.sql
Restoring a Single Table:
Using a .sql file:
mysql -u username -p db_name mysql> source full_path/table_name.sql
Alternatively:
mysql -u username -p db_name < path/to/table_name.sql
Restoring from a compressed .sql.gz file:
Dumping the data:
mysqldump db_name table_name | gzip > table_name.sql.gz
Restoring the data:
gunzip < table_name.sql.gz | mysql -u username -p db_name
The above is the detailed content of How Do I Backup and Restore a Single MySQL Table?. For more information, please follow other related articles on the PHP Chinese website!