Want a quick and dirty way to Truncate all the tables in a MySQL DB? You can use the following one line script.
mysqldump -ppassword YourDBName –no-data dumpfile | mysql dumpfile
What this does is uses mysqldump to output all the tables in the database “YourDBName” into a dump file. This dump file contains drop statements, and create table statements for each table in the database. What this effectively does is drops every table, and recreates it WITHOUT any data inside. Be very careful, since this is a very powerful script, it has the ability to completely wipe out your database with no hope of recovery unless you have a current backup.
For additional ways to execute specific commands against all tables in a DB, look into using mk-find in Maatkit, it is an excellent tool for advanced MySQL scripting.
Related articles
- Exiting a MySQL Stored Procedure in the middle of the code (prodromus.com)
- MySQL 5.5.8 and Percona Server on Fast Flash card (Virident tachIOn) (mysqlperformanceblog.com)

