63
57

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[MySQL] 全テーブルのデータを一括で削除

Posted at

テーブルが100個くらいあって、その全てのテーブルのデータを一発で削除したくなったりします。

そんなこと、たわいもないことかと思ったのですが、truncateでもdeleteでも出来ないし、結局、以下のようにやっております。

$ mysql -u root [db_name] -N -e 'show tables' | while read table; do mysql -u root -e "truncate table $table" [db_name]; done
63
57
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
63
57

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?