【MySql 存储过程】一键删(li)库(zhi)
DROP PROCEDURE IF EXISTS dbClear; DELIMITER $$ CREATE PROCEDURE dbClear() BEGIN DECLARE indexOfDb INT DEFAULT 0; SET @dbCount = 0; SELECT count(*) FROM information_schema.schemata WHERE schema_name LIKE 'lxmajs_%' INTO @dbCount; WHILE indexOfDb < @dbCount DO SET @runSql = ''; SELECT concat('drop database ',schema_name) FROM information_schema.schemata WHERE schema_name LIKE 'lxmajs_%' LIMIT 1 INTO @runSql; PREPARE stmt FROM @runSql; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET indexOfDb = indexOfDb + 1; END WHILE; END $$ CALL dbClear();
使用存储过程,删除 lxmajs_ 开头的数据库。