Clear data in MySQL table with PHP?


Question

How do I clear all the entries from just one table in MySQL with PHP?

1
18
12/16/2015 2:29:39 AM

The simplest way to do it, if you have the privileges, is:

DROP DATABASE dbName;
CREATE DATABASE dbName;
USE DATABASE dbName;

The alternative is to query the information_schema database for triggers, stored routines (procedures and functions), tables, views and possibly something else, and drop them individually.

Even after this, your database might still not be in the same state as a newly created one, since it might have a custom default character set and collation set. Use ALTER DATABASE to change that.

As features keep getting added (events...) you'll have more and more work this way. So really, the only way to completely empty the database is to drop it and re-create it.

15
4/7/2009 2:15:31 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon