Eliminare tutte le tabelle in un Database MySQL

From RVM Wiki
Revision as of 08:02, 29 September 2020 by Gabriele.vivinetto (talk | contribs) (Created page with "First, disable foreign key check: echo "SET FOREIGN_KEY_CHECKS = 0;" > ./temp.sql Then dump the db with no data and drop all tables: mysqldump --add-drop-table --no-data...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

First, disable foreign key check:

echo "SET FOREIGN_KEY_CHECKS = 0;" > ./temp.sql

Then dump the db with no data and drop all tables:

mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' >> ./temp.sql

Turn the foreign key check back on:

echo "SET FOREIGN_KEY_CHECKS = 1;" >> ./temp.sql

Now restore the db with the dump file:

mysql -u root -p db_name < ./temp.sql

Riferimenti