Truncating all tables in a database is a common problem which
arises a lot during testing or debugging.
One of the most common answers to this question is to drop &
recreate the database, most likely utilizing the shell. For
example, something like this:
mysqldump --add-drop-table --no-data [dbname] | mysql
[dbname]
This dumps the entire schema structure to disk, without dumping any data, and with commands for dropping existing tables. When loading it back into mysql, it essentially truncates all the tables in the database. Basically, this is a decent solution for many uses.
We had a requirement for a solution that needed these additional features:
- Does not require shell (We work with both Linux and Windows)
- Resides inside the MySQL Server (To minimize outside dependencies - for example - the mysql command line client)
- Can truncate only specified tables using a …