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.
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
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
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!