메뉴 건너뛰기

XEDITION

DB

mysql mysql table 전체 삭제

하서기 2020.03.19 16:42 조회 수 : 898

 

편하게 데이터베이스를 날리고 다시 생성하면 편하지만..

 

그럼 계정 권한을 다시 만들어 주는것도 일이다..

 

아래의 스크립트를 통해서 테이블 전체 삭제 가능..

 

SET @tables = NULL;

SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables

  FROM information_schema.tables

  WHERE table_schema = 'DB이름 입력'; -- specify DB name here.

 

SET @tables = CONCAT('DROP TABLE ', @tables);

PREPARE stmt FROM @tables;

EXECUTE stmt;

DEALLOCATE PREPARE stmt;

 

 

 # 실행 예시

mysql> mysql -uuserId -p;


mysql> SET @tables = NULL;
mysql> SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
      -> FROM information_schema.tables
      -> WHERE table_schema = 'delete of database name';

mysql> SET @tables = CONCAT('DROP TABLE ', @tables);

mysql> PREPARE stmt FROM @tables;
mysql> EXECUTE stmt;
mysql> DEALLOCATE PREPARE stmt;

 

 

위로