Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

By default, mysqldump will be taking the backup of an entire database. I want to back up a single table in the MySQL. 

Will it be possible? If so how can I restore it?

1 Answer

0 votes
by (12.7k points)
edited by

Dumping and restoring a single table from .sql:

Dump

mysqldump db_name table_name > table_name.sql

Dumping from a remote database

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

Restore

mysql -u <user_name> -p db_name

mysql> source <full_path>/table_name.sql

or in one line:

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

Dumping and restoring a single table from a compressed (.sql.gz) format:

Dump

mysqldump db_name table_name | gzip > table_name.sql.gz

Restore

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

Want to Learn SQL to get expertise in the concepts of SQL? Join the SQL Course and get certified.

Watch the below MySQL video tutorial to gain more knowledge on MySQL

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...