如何删除mysql中数据库的所有表中的所有行

时间:2022-12-25 09:17:31

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

我有一个包含近500个表的数据库,我想删除所有表的所有记录。如何实现这一目标。专家请帮忙......

3 个解决方案

#1


5  

The simplest way is to drop and recreate the database structure using these shell commands:

最简单的方法是使用以下shell命令删除并重新创建数据库结构:

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

Insert mysql credentials as required, eg -u root -psecret -h localhost

根据需要插入mysql凭据,例如-u root -psecret -h localhost

#2


2  

check this other question on *

在*上查看另一个问题

also, it would be useful to know if you want to use just sql or also any scripting language.

另外,知道是否只想使用sql或任何脚本语言会很有用。

#3


2  

TRUNCATE tableName;

This will empty the contents of the table. check 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]);
}
?>

#1


5  

The simplest way is to drop and recreate the database structure using these shell commands:

最简单的方法是使用以下shell命令删除并重新创建数据库结构:

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

Insert mysql credentials as required, eg -u root -psecret -h localhost

根据需要插入mysql凭据,例如-u root -psecret -h localhost

#2


2  

check this other question on *

在*上查看另一个问题

also, it would be useful to know if you want to use just sql or also any scripting language.

另外,知道是否只想使用sql或任何脚本语言会很有用。

#3


2  

TRUNCATE tableName;

This will empty the contents of the table. check 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]);
}
?>