Clear All From Database Tables

I have a database with large tables and I want to clear the data from the tables, how can I do this?

how to do a for loop for each table in the database DELETE FROM table_name;

Thank.

+3
source share
3 answers

Another alternative

  • use mysqldump only for table dump schema
  • use a table with the inscription
  • when you have a dump file execute it
  • the whole table will be deleted and recreated

If you want to reset your auto increment,
then make changes to the dump file to reset it


if you are using linux this can be done using a bash script like

for table in $(mysql -N <<<"show tables from your_db")
do
  mysql -N <<< "truncated $table"
done
+1
source

- script, sql. linux:

echo "select concat('truncate ', table_name, ';') as '' from \
  information_schema.tables where table_schema='YOURDATABASE';"\
  |mysql -u USER -p > /tmp/truncate-all-tables.sql
+1

- DELETE TRUNCATE .sql, . ( , , SELECTable.)

, DELETE, , auto_increment . ( reset 1, "TRUNCATE <table name>;".)

0

Source: https://habr.com/ru/post/1788796/


All Articles