How to empty all rows from all tables in mysql (in sql)

TRUNCATE tableName;

This will empty the contents of the table.

Edit in response to the Q edit:
It seems from my quick test that you will have to do at least 2 queries as it seems that “show tables” cannot be used as a sub query, I don’t know how to do this in bash so here is a PHP example, hopefully it will help.

<?php      
mysql_connect('localhost', 'user', 'password');
$dbName = "database";
mysql_select_db($dbName); /*added semi-colon*/
$result_t = mysql_query("SHOW TABLES");
while($row = mysql_fetch_assoc($result_t))
{
   mysql_query("TRUNCATE " . $row['Tables_in_' . $dbName]);
}
?>

At a minimum this needs some error handling.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)