将单个表从 mysqldump 数据库备份恢复到同一数据库中的不同表?

发布于 2024-08-24 16:20:52 字数 106 浏览 4 评论 0原文

我有一个 3.5GB 的数据库转储。有没有办法使用 mysqladmin 或在 FreeBSD 6 上运行的其他常用命令行应用程序将该文件中的单个表恢复到同一数据库中不同名称的表,而无需编辑该文件?

I've got a 3.5gb database dump. Is there a way to restore just a single table from that file to a differently named table in the same database without editing the file, using mysqladmin, or some other commonly available command line application that runs on FreeBSD 6?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请爱~陌生人 2024-08-31 16:20:52

您需要在restore-db 中创建表并运行如下操作:

grep "^INSERT INTO table" dump-file | mysql -u user -p restore-db

首先确保您的模式匹配正确。

You would need to create the table in restore-db and run something like:

grep "^INSERT INTO table" dump-file | mysql -u user -p restore-db

First make sure that your pattern matches correctly.

戏蝶舞 2024-08-31 16:20:52
cat THE_DUMP_FILE.SQL | sed -n "/^-- Table structure for table \`THE_TABLE_NAME\`/,/^-- Table structure for table/p" > THE_OUTPUT_SQL_FILE_NAME

我在谷歌上搜索了一段时间,这个解决方案对我来说非常有用,并且似乎是大型转储文件最快的解决方案之一,我的想法来自:
http://code.openark.org/blog /mysql/on-restoring-a-single-table-from-mysqldump

cat THE_DUMP_FILE.SQL | sed -n "/^-- Table structure for table \`THE_TABLE_NAME\`/,/^-- Table structure for table/p" > THE_OUTPUT_SQL_FILE_NAME

I googled around for a while on this, this solution worked great for me, and seemed to be one of the fastest solutions for a large dump file, I got the idea from:
http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文