DBMS (MySQL)

[DBMS] DCL

(งᐛ)ว 2023. 8. 4. 21:39
728x90

[DCL _ Data Control Language]

MySQL 내부 데이터 제어하는 언어 

사용자 추가, 삭제, 권한부여, 권한회수 등

데이터의 보안, 무결성, 회복 등을 정의하는데 사용 

 

set SQL_SAFE_UPDATES=0; *안전모드해제 

use MySQL;
select host, user from user;  *사용자 추가하기 전, 먼저 현재 사용자 계정 확인

 

 

사용자 추가 및 삭제

create user 유저ID;

create user 유저ID@호스트 identified by '비밀번호';

delete from user where user='유저ID';

drop user 유저ID@호스트;

 

#유저 id(user_sample1) 추가 _ 비밀번호X
create user user_sample1;

#유저 id(user_sample2) 추가 _ 호스트(localhost) pw(1234)
create user user_sample2@localhost identified by '1234';


#삭제방식 _ 비밀번호X
delete from user where user = 'user_sample1';

#삭제방식 _ 비밀번호O
drop user user_sample2@localhost;

 

 

 

GRANT

사용자에게 권한 부여 명령

grant 권한타입 on DB명.테이블명 to 유저ID@localhost;

 

sample유저에게 sample2 데이터베이스 내부에 있는 tableA라는 테이블의 권한(all, select 등)을 부여하겠다.

grant all on sample2.tableA to sample@localhost; 

grant select on sample2.tableA to sample@localhost;

grant insert on sample2.tableA to sample@localhost;

grant update on sample2.tableA to sample@localhost;

grant delete on sample2.tableA to sample@localhost;

grant create on sample2.tableA to sample@localhost;

grant drop on sample2.tableA to sample@localhost;

 

 

REVOKE

사용자에게 준 권한 회수 명령 

revoke 권한타입 on DB명.테이블명 from 유저ID@localhost;

 

sample유저에게 sample2 데이터베이스 내부에 있는 tableA라는 테이블의 권한(all, select 등)을 회수하겠다.

revoke all on sample2.tableA from sample@localhost;

revoke select on sample2.tableA from sample@localhost;

revoke insert on sample2.tableA from sample@localhost;

revoke update on sample2.tableA from sample@localhost;

revoke delete on sample2.tableA from sample@localhost;

revoke create on sample2.tableA from sample@localhost;

revoke drop on sample2.tableA from sample@localhost;

 

728x90