我正在寻找一个 Unix shell 脚本,它将截断模式中的所有表。已经有人问过类似的问题,但我有一些额外的要求,这使得所提供的答案都不令人满意:
- 必须是 Unix shell 脚本(即没有 python、perl、PHP)
- 脚本必须按照外键约束的顺序截断表
- 我宁愿不必使用存储过程
提前致谢, 唐
最佳答案
像这样厚颜无耻的东西怎么样:
mysqldump --no-data mydb | mysql mydb
获取模式转储并将其重播到数据库中!
或者,查看 mk-find在 Maatkit ,你应该能够做这样的事情:
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.
关于sql - 截断所有 MySql 表的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/461863/