show databases;
use union_sample;
show tables;
# 차집합 -> 테이블 간의 교집합(inner join)을 제외하고 기준이 되는 테이블에 있는 데이터(레코드)만 보이게 하는 것
# 서브쿼리를 이용한 방식
select str from a where str not in(
select distinct str from b);
# 조인을 이용한 방식
select a.str from a left join b on a.str = b.str
where b.str is null;
# 첫 번째 실습
# 1
select no from tableA where no not in(
select distinct no from tableB);
# 2
select id from tableA where id not in(
select distinct id from tableB);
# 곱집합 -> 모든 요소가 곱해져서 결과가 나옴
# from 절에 쓰는 방식
select * from a, b;
# cross join 사용 방식
select * from a cross join b;
# inner join 사용 방식
select * from a inner join b on 1=1;
# DCL
set SQL_SAFE_UPDATES = 0; # 안전모드 해제
# set SQL_SAFE_UPDATES = 1; # 안전모드 설정
use mysql;
select * from user;
select host, user from user;
# 사용자(USER) 추가
create user user1; # user1을 추가함
# user2 추가 -> localhost 사용, 비밀번호 : 1234
create user user2@localhost identified by '1234';
# 사용자(USER) 삭제
delete from user where user='user1'; # 이름으로 삭제(조건 사용)
drop user user2@localhost; # drop 방식
# GRANT -> 권한 부여
create user kkh@localhost identified by '1234';
# union_sample이라는 DB 내부의 a 테이블을 조작할 수 있는 모든 권한을 부여한다 -> kkh@localhost라는 사용자에게
grant all on union_sample.a to kkh@localhost;
revoke all on union_sample.a from kkh@localhost;
grant select on union_sample.a to kkh@localhost;
revoke select on union_sample.a from kkh@localhost;
grant update on union_sample.a to kkh@localhost;
revoke update on union_sample.a from kkh@localhost;
grant insert on union_sample.a to kkh@localhost;
revoke insert on union_sample.a from kkh@localhost;
grant delete on union_sample.a to kkh@localhost;
revoke delete on union_sample.a from kkh@localhost;
grant alter on union_sample.a to kkh@localhost;
revoke alter on union_sample.a from kkh@localhost;
grant drop on union_sample.a to kkh@localhost;
revoke drop on union_sample.a from kkh@localhost;
grant create on union_sample to kkh@localhost; # DB에 대한 권한 주기
revoke create on union_sample from kkh@localhost;
drop user kkh@localhost;
# 두 번째 실습
drop database if exists hospital;
create database hospital;
use hospital;
create table doctor(
id int primary key);
use mysql;
create user kevin@localhost identified by 'p@ssw0rd';
grant select on hospital.doctor to kevin@localhost;
grant insert on hospital.doctor to kevin@localhost;
grant update on hospital.doctor to kevin@localhost;
grant delete on hospital.doctor to kevin@localhost;
create user merry;
grant create on hospital to merry;
drop user merry;
drop user kevin@localhost;
create user hans@localhost identified by '20240129';
grant all on hospital.doctor to hans@localhost;
drop user hans@localhost;
drop database hospital;
'(학) (공) (디)' 카테고리의 다른 글
02.05(10일차) (0) | 2024.02.06 |
---|---|
01.31(9일차) -자바연동해서 데이터구축 (1) | 2024.02.05 |
01.27(7일차) (0) | 2024.01.27 |
01.24(6일차) (0) | 2024.01.24 |
01.22(5일차) (0) | 2024.01.22 |