Home >Database >Mysql Tutorial >How Do I Backup and Restore a Single MySQL Table?

How Do I Backup and Restore a Single MySQL Table?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-01 05:33:11609browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn