How to restore a specific table from mysqldump

血红的双手。 提交于 2019-12-13 14:09:37

问题


I have a mysqldump file which was taken using the following command. mysqldump -u root --password=<passwd> 'gss-app' table1 table2 ... tableN --skip-triggers --skip-add-drop-table --skip-lock-tables --compact --no-create-info --quick | bzip2 -c > /var/backups/gss-app.sql.bz2

I have decompressed the dump and want to restore a table named sd_images. As the create table and drop table statements are skipped in the command used the dump file starts INSERT INTO table_name for each table. Could anyone please help me to restore only sd_images table into my database.?


回答1:


There is already a stackoverflow answer for this Can I restore a single table from a full mysql mysqldump file?

My preferred approach would be to load the entire dumpfile into a new database, then copy just the table you want into your target database rather than use sed on the dumpfile. But that's just me.




回答2:


I took a backup of the database structure only using

mysqldump -u root -p<password> --no-data gss-app > gss-app-structureonly.sql

and then restored the structure to a new database 'restore'.

After that I restored the huge mysql dump on the new database 'restore' and I could see the data in the new database. But still the old dump is missing few tables. I ran a full backup again by removing all the --skip options. Hope it will be fine hereafter. Thanks.



来源:https://stackoverflow.com/questions/30002687/how-to-restore-a-specific-table-from-mysqldump

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!