example_或e _
我想删除所有与前缀e_匹配的数据库,以便删除e_database1,e_database2等。
不起作用的命令:
mysql drop database e_% mysql drop database e _ *
我不是在寻找给定数据库中的所有表,而是查找给定MySQL服务器中的所有数据库。
答案 0 :(得分:0)
你可以使用这样的存储过程执行此操作:
/* Start stored proc */
DELIMITER //
DROP PROCEDURE IF EXISTS db_clean_up //
CREATE PROCEDURE db_clean_up
(
)
BEGIN
declare done bit default false;
declare deleted varchar(255);
-- Drop DBs
DECLARE cur1 CURSOR FOR SELECT
SCHEMA_NAME
FROM information_schema.SCHEMATA
WHERE SCHEMA_NAME LIKE 'db_prefix%';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
createLoop: LOOP
FETCH cur1 INTO deleted;
IF done THEN
LEAVE createLoop;
END IF;
SET @query = CONCAT('DROP DATABASE `', deleted, '`;');
PREPARE stmt1 FROM @query;
EXECUTE stmt1;
END LOOP createLoop;
CLOSE cur1;
END //
delimiter ;
/* End stored proc */