Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring a MySQL table back to the database

Tags:

I have a trouble in restoring MySQL table back to the database from command line. Taking backup of a table is working with mysqldump.Taking backup and restoring of a database is also working properly. I have used:

mysql -uroot -p DatabaseName TableName < path\TableName.sql

Thanks in advance

like image 438
Luna Avatar asked Mar 14 '12 05:03

Luna


People also ask

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

We can just take a consistent backup of the whole dataset but this will generate a large, single file with all the data. To restore the single table we would have to extract data for the table from that file.

How can we take a backup of a MySQL table and how can we restore it?

You can simple copy the table files of a MySQL database to a separate location and accomplish a backup. Later, when necessary, you simply copy them back to the original location to restore the database. If you are using WAMP server for MySQL, then you can find table files within wamp > bin > mysql > mysql5.

Which command is used to restore the database in MySQL?

Generate backup using mysqldump utility. Mysqldump is a command-line utility that is used to generate the logical backup of the MySQL database. It produces the SQL Statements that can be used to recreate the database objects and data.


2 Answers

Ah, I think I see the problem here.

Your backup script looks fine. tbl_name works correctly as the optional 2nd argument.

To restore, you should simply run

mysql -uroot -p DatabaseName < path\TableName.sql 

Running man mysql would have shown you the correct arguments and options

mysql [options] db_name

As your backup script only contains one table, only that table will be restored into your database.

like image 65
Phil Avatar answered Sep 22 '22 05:09

Phil


Taking backup

mysqldump -u -p mydatabase table1 > database_dump.sql 

restoring from backup flie need not include table name

mysql -u -p mydatabase < database_dump.sql 
like image 29
Naveen Kumar Avatar answered Sep 20 '22 05:09

Naveen Kumar