Home >Database >Mysql Tutorial >How Can I Securely Backup and Restore Individual Tables in MySQL?

How Can I Securely Backup and Restore Individual Tables in MySQL?

Susan Sarandon
Susan SarandonOriginal
2024-11-30 13:48:12316browse

How Can I Securely Backup and Restore Individual Tables in MySQL?

Securing Single Table Backups in MySQL

When managing substantial databases, it's often necessary to backup specific tables rather than the entire database. MySQL's mysqldump utility offers a flexible backup solution, allowing you to retrieve data from individual tables.

Dumping a Single Table

To dump the data from a single table named 'table_name' in the database 'db_name':

mysqldump db_name table_name > table_name.sql

Alternatively, if the database resides on a remote server, use:

mysqldump -u <db_username> -h <db_host> -p db_name table_name > table_name.sql

Restoring the Table

To restore the backed-up table, follow these steps:

mysql -u <user_name> -p db_name
mysql> source <full_path>/table_name.sql

Or, in a single line:

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

Compressed Backup Formats

For more efficient backup storage, you can utilize compressed formats.

Dump with Compression:

mysqldump db_name table_name | gzip > table_name.sql.gz

Restore from Compressed Backup:

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

The above is the detailed content of How Can I Securely Backup and Restore Individual Tables in MySQL?. 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