Last active
December 14, 2015 02:38
-
-
Save 66Ton99/5014611 to your computer and use it in GitHub Desktop.
Drop all data in the current DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Server version 5.5.20 | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8 */; | |
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | |
/*!40103 SET TIME_ZONE='+00:00' */; | |
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | |
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | |
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | |
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | |
DELIMITER $$ | |
CREATE PROCEDURE drop_data_like(pattern VARCHAR(255), db VARCHAR(255)) | |
begin | |
DECLARE truncate_table VARCHAR(255) DEFAULT ''; | |
DECLARE done INT DEFAULT 0; | |
DECLARE cur1 CURSOR FOR SELECT CONCAT('TRUNCATE TABLE ', db, '.', info.table_name) | |
FROM information_schema.tables AS info | |
WHERE info.table_schema=db AND info.table_name LIKE pattern; | |
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; | |
OPEN cur1; | |
read_loop: LOOP | |
FETCH cur1 INTO truncate_table; | |
SET @sql = truncate_table; | |
IF done THEN LEAVE read_loop; END IF; | |
PREPARE stmt FROM @sql; | |
EXECUTE stmt; | |
DROP PREPARE stmt; | |
END LOOP; | |
CLOSE cur1; | |
END$$ | |
DELIMITER ; | |
CALL drop_data_like('%%', DATABASE()); | |
DROP PROCEDURE drop_data_like; | |
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | |
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | |
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | |
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | |
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment