微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于截断所有MySql表的shell脚本

我正在寻找一个Unix shell脚本,它将截断模式中的所有表.已经提出了一个类似的问题,但是我还有一些额外的要求,这些要求使得所提供的答案都不令人满意

>必须是Unix shell脚本(即没有python,perl,PHP)
>脚本必须按照遵守外键约束的顺序截断表
>我不想使用存储过程

提前致谢,

解决方法:

像这样厚脸皮的东西怎么样:

MysqLdump  --no-data mydb | MysqL mydb

获取模式的转储并将其重放到数据库中!

或者,在Maatkit中查看mk-find,您应该能够做到这样的事情:

mk-find -exec "truncate %s"

mk-find的描述:

This tool is the MysqL counterpart to
the UNIX ‘find’ command. It accepts
tests (such as “find all tables larger
than 1GB”) and performs actions, such
as executing sql (”DROP TABLE %s”).
With this tool at your disposal you
can automate many tedious tasks, such
as measuring the size of your tables
and indexes and saving the data for
historical trending, dropping old
scratch tables, and much more. It is
especially useful in periodic
scheduled tasks such as cron jobs.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐