How to delete all rows in the entire database table in mysql

I had a database with almost 500 tables, and I want to delete all records of all tables. How to achieve this. Experts Please help ...

+3
source share
3 answers

The easiest way is to reset and recreate the database structure using these shell commands:

mysqldump -d dbname > structure.sql
mysqladmin drop dbname
mysqladmin create dbname
mysql dbname < structure.sql

Enter mysql credentials as needed e.g. -u root -psecret -h localhost

+5
source

fooobar.com/questions/221102 / ...

It would also be useful to know if you want to use only sql or any scripting language.

+2
source
TRUNCATE tableName;

This will empty the contents of the table. here

<?php
mysql_connect('localhost', 'user', 'password');
$dbName = "database";
mysql_select_db($dbName)
$result_t = mysql_query("SHOW TABLES");
while($row = mysql_fetch_assoc($result_t))
{
   mysql_query("TRUNCATE " . $row['Tables_in_' . $dbName]);
}
?>
+2
source

Source: https://habr.com/ru/post/1793207/


All Articles