MySQL – A simple script to truncate all MySQL tables in a Database
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.
- MySQL – Select rows from a table when a field starts with a number
- B-17 E-Z Goin’ and the Sonderkommando Elbe – Buchen Raid