Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take backup of a single table in a MySQL database?

By default, mysqldump takes the backup of an entire database. I need to backup a single table in MySQL. Is it possible? How do I restore it?

like image 940
Mandar Pande Avatar asked Jul 13 '11 17:07

Mandar Pande


People also ask

How do I export just one table in MySQL?

in order to dump a set of one or more tables, shell> mysqldump [options] db_name [tbl_name ...] Show activity on this post. This will export the tableName to the file tableName.

Can you backup a single table in SQL Server?

Step 1 : Right click on the database and choose Tasks –> Generate Scripts. Step 2 : Select the database from which you need to take a backup of the table. Step 3 :You will see the Table/View options on the screen while scrolling down. Select the table which you want to back up and Hit next button.

Can I restore a single table from a full MySQL Mysqldump file?

Use the sed command on your bash shell to separate the data of the table that you want to restore. For example, if we want to restore only the “film_actor” table to “sakila” database we execute the script below.


1 Answers

Dump and restore 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 

For further reference:

http://www.abbeyworkshop.com/howto/lamp/MySQL_Export_Backup/index.html

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


Dump and restore a single table from a compressed (.sql.gz) format

Credit: John McGrath

Dump

mysqldump db_name table_name | gzip > table_name.sql.gz 

Restore

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

like image 198
7 revs Avatar answered Sep 25 '22 23:09

7 revs