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?
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With