在一个命令中截断 MySQL 数据库中的所有表?
2022-01-30 00:00:00
mysql
Is there a query (command) to truncate all the tables in a database in one operation? I want to know if I can do this with one single query.
解决方案Drop (i.e. remove tables)
mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "drop table $table" DATABASE_NAME; done
Truncate (i.e. empty tables)
mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "truncate table $table" DATABASE_NAME; done
相关文章