用于截断所有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.

上一篇:mysql的十二条基本语句


下一篇:[Postgres] Removing Data with SQL Delete, Truncate, and Drop