How do I clear all data in a MySQL database while maintaining the table structures?

5

1

Using MySQL CLI, how can I remove all data in a given MySQL database without changing any table's structures?

superuser

Posted 2012-05-29T17:46:53.987

Reputation: 3 297

That works for a single table, not all – Mawg says reinstate Monica – 2017-01-15T10:43:31.840

This is in Linux by the way. – superuser – 2012-05-29T17:48:20.927

1Have you tried delete * from * just off the top of my head. – Yitzchak – 2012-05-29T17:52:05.683

Answers

11

truncate example:

truncate table friends

– will delete all records from the table and also rebuild the table, thus resetting the auto_increment counter.

Logman

Posted 2012-05-29T17:46:53.987

Reputation: 3 452

can you truncate an entire database, or do you have to go table by table? – Thufir – 2014-06-20T13:53:36.880

That works for a single table, not all – Mawg says reinstate Monica – 2017-01-15T10:43:58.757

11

keaton_fu

Posted 2012-05-29T17:46:53.987

Reputation: 671

That works for a single table, not all – Mawg says reinstate Monica – 2017-01-15T10:44:04.443