There is a much simpler way. In one line at the command prompt, type:
mysql -u root -p[password] --skip-column-names [database] -e "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='[database]' AND TABLE_NAME NOT IN ('[table 1]', '[table 2]',..'[table n]');" | cut -f1 | sed -r 's/(.*)/DROP TABLE IF EXISTS \1;/' | mysql -u root -p[password] [database]
You may receive two warnings about the inclusion of passwords in the command. If this could be a problem, you can clear the command history to “remove evidence” :-)
history -c
source
share