Skip to content

Truncate all tables in a MySQL database

To truncate (not dropping, truncating only deletes all table rows) all tables in a MySQL database, run this command and replace <database name> with the name of the database that should be truncated:

mysql -Nse 'show tables' <database name> | while read table; do mysql -e "truncate table $table" <database name>; done

(source)

One Comment

  1. launaelizondo launaelizondo

    I want to say that this post is awesome,
    nice written and come with almost all important infos. I’d like to peer more posts like this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.