Delete data from all tables in MYSQL

前端 未结 16 1734
自闭症患者
自闭症患者 2020-12-13 09:17

I have 100 tables, 40,000 rows in each table. I want to go into MySQL and delete all rows from all tables.

...in 1 statement, if p

16条回答
  •  再見小時候
    2020-12-13 10:08

    This one works for me in MySQL 5, and it is specific to tables:

    echo 'show tables' | mysql --skip-column-names -u root YOUR_DB | awk '{print "truncate table " $0 ";"}' | mysql -u root YOUR_DB

    Replace YOUR_DB by the name of your database. You have to provide your password twice, so you have a chance to think it again ... ;-)

提交回复
热议问题