Eliminare tutte le tabelle in un Database MySQL: Difference between revisions

From RVM Wiki
Jump to navigation Jump to search
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..."
(No difference)

Revision as of 08:02, 29 September 2020

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