I want to keep t1,t2 and drop all other tables.
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
You can use
information_schema
to find table names, and even format the results as a bunch ofDROP
statements.(The
DATABASE()
function returns the currentlyuse
'd database.)Using
PREPARE
andEXECUTE
, you could even avoid copy & paste, and (in MySQL 5.0.13 and later) write a stored procedure to do this.You could use mysqldump to generate a list of DROP TABLE statements, filter out the ones you don't want, then pipe it back into the mysql client. Here's how we build that up
First, here's a list of DROP TABLE table statements for the database
Now we can pipe that through grep with -v to invert the match - we want statements which don't mention the tables we're retaining (another way to do this would be --ignore-table options to mysqldump)
Finally, once you're confident, you can pipe that back into mysql