drop tables using regex - MySQL
mysql
Solution
You can use this MySQL procedure:
DELIMITER $$
CREATE PROCEDURE drop_tables_like(pattern VARCHAR(255), db VARCHAR(255))
BEGIN
SELECT @str_sql:=CONCAT('drop table ', GROUP_CONCAT(table_name))
FROM information_schema.tables
WHERE table_schema=db AND table_name LIKE pattern;
PREPARE stmt from @str_sql;
EXECUTE stmt;
DROP prepare stmt;
END$$
DELIMITER ;
For dropping all tables starting with 'a' in 'test1' database you can run:
CALL drop_tables_like('a%', 'test1');
Reference: http://dev.mysql.com/doc/refman/5.5/en/drop-table.html
Problem
I have a bunch of tables in a `MySQL` database, some of them starting with phpbb_* which I wanted to delete all of them. Does someone know a way to do so instead of doing ``` drop table <tablename>; ``` every single time? Like a regex? ``` drop table phpbb* ``` or something like?