Mysql: Drop / Truncate all tables in a database.

I had a need today to maintain the database schema but clear the data itself.

Here’s the little command line snippet.

mysql -u -p -D  -Nse 'show tables' | while read TABLE; do mysql -u -p -D -e "truncate table $TABLE"; done

 

Gareth
Buy Me A Coffee
back arrowBack to Index