有没有办法截断 MySQL 模式中的大多数表?
我正在寻找一个查询(或一系列)来截断我的架构(有几百个表)中的所有表,除了 4 个特定的表。 我该怎么做呢? 谢谢!
I'm looking for a query (or series of) to TRUNCATE all tables in my schema (which has a few hundred tables) EXCEPT for a 4 specific ones. How might I go about doing that? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种方法可能是将这四个表复制到新架构中,然后删除原始数据库架构。
Another method could be that you copy those four tables in a new schema and then delete the original database schema.
*尼克斯一行:
*nix one-liner:
我相信您必须用您最喜欢的任何语言编写脚本。 您可以从 information_schema 数据库中获取架构中的表列表,然后迭代它们,截断您想要的任何表。
查询类似于:
编辑:这是一个使用 Perl 的示例:
I believe you'll have to write a script in whatever language you like the most. You can get a list of the tables in the schema from the information_schema db, then iterate over them, truncating any that you feel like.
Query would be something like:
Edit: Here's an example using Perl: