sql - 截断所有 MySql 表的 shell 脚本

标签 sql mysql bash truncate

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

  • 必须是 Unix shell 脚本(即没有 python、perl、PHP)
  • 脚本必须按照外键约束的顺序截断表
  • 我宁愿不必使用存储过程

提前致谢, 唐

最佳答案

像这样厚颜无耻的东西怎么样:

mysqldump  --no-data mydb | mysql mydb

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

或者,查看 mk-findMaatkit ,你应该能够做这样的事情:

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/

相关文章:

mysql - Innodb 和 Myisam 指数之间的差异?

mysql substring/left 命令未返回正确的字符数

Bash:用管道杀死

mysql - 如何以 15 分钟的间隔从多个表中提取值?

sql - 避免 "An INSERT EXEC statement cannot be nested"

sql - 在 InnoDB 上实现类全文搜索的任何方法

php - 如何在 MySQLi 中为我的数据库创建表

mysql - 获取连接表中没有匹配记录的记录

php - 动态数据透视表 mysqli 和 PHP

linux - 通过 SSH 连接代理命令