Mysql drop many tables
Thanks to Nick's blog I found the following:
mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | grep [PREFIX]
You don't have to use the second grep. The [PREFIX] refers to the "wildcard" I used because I didn't want to drop all the tables but only some. If you execute it you will see a list of DROP.... and you can do a copy paste to choose what you want.
Nick wanted to drop all tables in the database so he used this :
mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]
Let's see an example. I am user velonis and the password is abcde. I want to find all the tables in database joomla with the prefix shop (like shop_items, shop_users etc) .What should I do?
mysqldump -u velonis -p abcde --add-drop-table --no-data joomla | grep ^DROP | grep shop
It will show me a list with DROP which I will copy and paste in the mysql command line.
The Academic Site of Velonis I. Petros


Comments