Just to add to the above answer, MYSQL returns an error ERROR 1046 (3D000): No database selected
if no database is selected before beginning the procedure. So prepend this statement use <<db_name>>;
to the above answer. The revised solution would be:
use <<db_name>>;
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 ;
CALL drop_tables_like('a%', '<<db_name>>');
Make sure you replace <> with the actual name of the database. Cheers!