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
Release: 2024-12-01 05:33:11
Original
682 people have browsed it

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
Copy after login

Exporting from a remote database:

mysqldump -u db_username -h db_host -p db_name table_name > table_name.sql
Copy after login

Restoring a Single Table:

Using a .sql file:

mysql -u username -p db_name
mysql> source full_path/table_name.sql
Copy after login

Alternatively:

mysql -u username -p db_name < path/to/table_name.sql
Copy after login

Restoring from a compressed .sql.gz file:

Dumping the data:

mysqldump db_name table_name | gzip > table_name.sql.gz
Copy after login

Restoring the data:

gunzip < table_name.sql.gz | mysql -u username -p db_name
Copy after login

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 of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template