강좌
클라우드/리눅스에 관한 강좌입니다.
데이터베이스 분류

mysqladmin으로 특정데이터베이스 삭제하기(drop)

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

mysqladmin으로 특정데이터베이스 삭제하기(drop)

 

 

 

 

 

앞의 예에서는 mysqladmin을 이용하여 새로운 데이터베이스를 생성하는 예를 보았다.

 

 

 

 

 이번에는 이와 반대로 mysqladmin 을 이용하여 이미 생성되어있는 데이터베이스를 삭제할 수도 있다.

 

 

 

 

 

 

사용형식 : mysqladmin -u root -p drop 삭제할데이터베이스명

 

 

 

 

위와같이 mysqladmin으로 존재하는 데이터베이스를 삭제하면 그 데이터베이스내에 저장되어있던 모든 테이블의 데이터들까지 모두 삭제되므로 주의하기 바란다.

 

 

 

 

 아래의 예는 앞의 예에서 생성하였던 linux300이라는 데이터베이스를 삭제한 예이다.

 

 

 

 

 

 

[root@RockyLinux ~]# mysqladmin -u root -p drop linux300

Enter password:

Dropping the database is potentially a very bad thing to do.

Any data stored in the database will be destroyed.

 

Do you really want to drop the 'linux300' database [y/N] y

Database "linux300" dropped

[root@RockyLinux ~]#

 

 

 

 

위의 예와 같이 mysqladmin으로 이미 존재하고있는 데이터베이스를 삭제하면 “Do you really want to drop the 'linux300' database [y/N]” 와 같은 메시지로 삭제확인하게 된다.

 

 

 

 

 이때 y를 입력하면 삭제가 되고 아무것도 입력하지 않거나 N를 입력하면 삭제되지 않는다.

 

 

 

 

 

 

아래는 위의 삭제확인 메시지에 y를 입력하여 linux300이라는 데이터베이스를 삭제한 후에 실제로 삭제가 되었는가를 확인하기 위하여 MYSQL에 접속하여 “show databases”명령어로 확인한 것이다.

 

 

 

 

 

 

[root@RockyLinux ~]# mysql -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 6

Server version: 10.5.16-MariaDB MariaDB Server

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]>

MariaDB [(none)]>

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sulinux            |

| temp_db            |

| temp_db2           |

| wpDB               |

+--------------------+

7 rows in set (0.000 sec)

 

MariaDB [(none)]>

 

 

 

 

확인한 바와같이 linux300이라는 데이터베이스는 존재하지 않는다.

 

 

 

 

 그리고 이미 말씀드린 바와같이 이렇게 삭제하면 그 데이터베이스에 존재하던 모든 데이터들이 삭제된다.

 

 

 

 

 

 

그리고 또 한가지 분명히 알아둬야 할 것이 있다.

 

 

 

 

 다음 예를 보자.

 

[root@RockyLinux ~]# cd /var/lib/mysql/

[root@RockyLinux mysql]# ll

합계 122932

-rw-rw----. 1 mysql mysql     32768  7 12 14:56 aria_log.00000001

-rw-rw----. 1 mysql mysql        52  7 12 14:56 aria_log_control

-rw-rw----  1 mysql mysql      2103  7 12 14:56 ib_buffer_pool

-rw-rw----. 1 mysql mysql 100663296  7 12 15:12 ib_logfile0

-rw-rw----. 1 mysql mysql  12582912  7 12 14:56 ibdata1

-rw-rw----  1 mysql mysql  12582912  7 12 15:12 ibtmp1

-rw-rw----. 1 mysql mysql         0  4 26 16:11 multi-master.info

drwx------. 2 mysql mysql      4096  4 26 16:11 mysql

srwxrwxrwx  1 mysql mysql         0  7 12 15:12 mysql.sock

-rw-rw----. 1 mysql mysql        16  4 26 16:11 mysql_upgrade_info

drwx------. 2 mysql mysql        20  4 26 16:11 performance_schema

drwx------  2 mysql mysql        20  6 16 11:23 sulinux

drwx------  2 mysql mysql        62  7 11 14:06 temp_db

drwx------  2 mysql mysql        20  7 11 14:26 temp_db2

drwx------  2 mysql mysql      4096  4 27 12:24 wpDB

[root@RockyLinux mysql]#

 

 

 

 

 

실제로 데이터베이스의 데이터가 저장되는 위치인 /var/lib/mysql/ 디렉토리에 위치한 linux300의 디렉토리가 삭제된다는 점도 꼭 기억하기 바란다.

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,035 명
  • 현재 강좌수 :  35,800 개
  • 현재 접속자 :  164 명