MySQL

SQL 문법, DCL 데이터 제어 언어 (통신/연결)

조충희 2025. 5. 13. 18:20

DCL

데이터 제어 언어

Data Control Language

 

주요명령어

GRANT
REVOKE

-- DCL 데이터 제어 언어
-- 현재 root 계정 (최고관리자)

create database mydb2;
use mydb2;

-- 사용자 생성 및 비밀번호 설정
-- 로컬에서만 접근 가능한 계정 user1 생성
-- 버전 5와 8의 명령어가 다르다. 현재 8 사용중
create user 'user1'@'localhost' identified by 'password123';

-- user1에 조회 권한만 부여해보자.
grant select on school.student to 'user1'@'localhost';

-- user1 계정 조회 권한 회수
revoke select on school.student from 'user1'@'localhost';

-- 원격 및 로컬에서 접근 가능한 id 생성과 권한부여
create user 'user2'@'%' identified by 'password123';
create user 'user2'@'localhost' identified by 'password123';

-- 권한 부여
grant select, insert, update, delete on school.student to 'user2'@'%';
grant select, insert, update, delete on school.student to 'user2'@'localhost';

user1의 권한 조회 상태, 조회(select) 기능만 사용 가능하다.
mysql 워크벤츠 프로그램 홈에서 user1로 비밀번호를 입력하여 접속해봤다.
mydb2 데이터베이스의 users 테이블을 조회(select)해보는 모습