如何在重命名某些表/列的同时导入 mysql 转储而不导入其他表/列?
我正在将遗留数据库导入到我们程序的新版本中,我想知道是否有一种方法可以不从转储中导入某些列/表,并在导入时重命名其他表/列?我知道理论上我可以编辑转储文件,但这似乎是一种黑客行为,到目前为止,我的编辑器都无法打开 1.3 GB 文件(是的,我已经在这里阅读了有关该问题的问题。不,到目前为止,没有一个答案对我有用。)。
建议?
I'm importing a legacy db to a new version of our program, and I'm wondering if there's a way to not import some columns/tables from the dump, and rename other tables/columns as i import them? I'm aware I could edit the dump file in theory, but that seems like a hack, and so far none of my editors can handle opening the 1.3 gb file (Yes, I've read the question about that on here. No, none of the answers worked for me so far.).
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过拒绝导入某些表的权限并使用 --force 作为命令行选项,可以不导入某些表。
不导入某些列或重命名它们是不可能的(至少不编辑转储文件或导入后进行修改)。
我的建议是:
如果您担心转储包含多个数据库,mysql 命令行工具有一个 -o 标志,可以仅导入一个数据库。
It's possible to not import some tables by denying permissions to do so, and using --force as a command line option.
Not importing some columns, or renaming them is not possible (at least without editing the dump file, or making modifications once imported).
My recommendation would be:
If you're worried the dump contains multiple databases, the mysql command line tool has a -o flag to only import the one.
我想说将其导入临时数据库并实时进行更改 - 可能应用执行必要操作的预构建脚本:
然后将完成的结果复制到生产数据库中。
这也可以很好地实现自动化。
与寻找编辑转储的工具相比,它可能会更快并且问题更少(或者,就像这些事情经常发生的那样,尝试五种不同的工具,但发现没有一个工作得很好)。
I'd say import it into a temporary database and do the changes live - possibly applying a pre-built script that does the necessary operations:
Then copy the finished result into the production database.
This can be very nicely automated as well.
It's likely to work out faster and with less problems than finding a tool that edits dumps (or, as so often with these things, trying out five different tools and finding out none works well).
假设您拥有两个数据库,您可以重命名 OldDB 中的所有表(只需确保前缀未在任何表名中使用,因为重命名回具有字符串替换)……
然后转储并导入到 NewDB 中。
这将为您提供(例如):
进一步阅读/基于:
Assuming you have both databases, you could rename all tables in OldDB (just make sure the prefix isn't used already in any table name, because renaming back has a string-replace) …
… then dump and import into NewDB.
This would give you (for example):
Further reading / based on: