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
Release: 2024-11-30 13:48:12
Original
191 people have browsed it

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

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

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

Or, in a single line:

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

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

Restore from Compressed Backup:

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

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!

source:php.cn
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