MySQL 의 테이블 스페이스는 놔두고 그 안의 모든 table 만 삭제하는 방법.


삭제 코드

다음 코드를 drop_table.sql 이라는 파일로 저장합니다.

drop_table.sql

SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
  FROM information_schema.tables
  WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;

SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1; 
SQL


실행

mysql command client 에서 삭제하려는 계정(Ex: user) 과 암호(Ex: secret), 테이블 스페이스를 입력하고 입력 파이프로 drop_table.sql 파일을 지정하면 모든 테이블이 삭제됩니다.

mysql -u user -psecret table_space < drop_table.sql
CODE


같이 보기


Ref