Delete data from all tables in MYSQL

前端 未结 16 1728
自闭症患者
自闭症患者 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:11

    Easiest method to truncate all tables while retaining schema.

    mysqldump -d -uuser -ppass --add-drop-table databasename > databasename.sql
    
    mysql -uuser -ppass databasename < databasename.sql
    

    Not sure if it will retain stored procedures as they are not in use where I work, but I use this regularly to reset databases.

    The -d switch on mysqldump means "don't dump data."

    The --add-drop-table prepends a DROP TABLE statement to every CREATE TABLE in the dump.

提交回复
热议问题