Alex Rivera | Logout

Truncate all tables in a MySQL database in one command?

Asked 2009-12-16T06:58:40.937
423

Is there a query (command) to truncate all the tables in a database in one operation? I want to know if I can do this with one single query.

Edit
Report

2 Answers

86

Use phpMyAdmin in this way:

Database View => Check All (tables) => Empty

If you want to ignore foreign key checks, you can uncheck the box that says:

[ ] Enable foreign key checks

You'll need to be running at least version 4.5.0 or higher to get this checkbox.

It's not MySQL CLI-fu, but hey, it works!

answered 2011-08-20T11:06:25.087
0

Soln 1)

mysql> select group_concat('truncate',' ',table_name,';') from information_schema.tables where table_schema="db_name" into outfile '/tmp/a.txt';
mysql> /tmp/a.txt;

Soln 2)

- Export only structure of a db
- drop the database
- import the .sql of structure 

-- edit ----

earlier in solution 1, i had mentioned concat() instead of group_concat() which would have not returned the desired result
answered 2013-03-19T13:22:05.780

Your Answer