본문 바로가기

공부 기록/Database

Database 사용자 생성과 권한 부여

 

사용자 추가

mysql -u root -p // 접속
use mysql;
select user, host from user; // 사용자 목록 조회

create user {user_id}@localhost identified by '{password}';

 


 

권한 부여

grant all privileges on {db_name}.* to {user_id}@localhost;
grant all privileges on *.* to {user_id}@'%'; // 모든 DB에 접근 가능
flush privileges; // 권한 반영

 

  • '%' : 어떤 클라이언트에서든 접근 가능
  • 'localhost' : 해당 컴퓨터에서만 접근 가능

 


 

권한 확인

show grants for {user_id}@localhost;
show grants for {user_id}@'%';

 


 

사용자 생성과 권한 부여 한 번에 하기

-  DB 이름은 connectdb, 사용자 계정 이름은 connectuser, 암호는 connect123!@# 일 때, 다음과 같이 명령을 수행한다.

grant all privileges on connectdb.* to connectuser@'%' identified by 'connect123!@#';
grant all privileges on connectdb.* to connectuser@'localhost' identified by 'connect123!@#';
flush privileges;

 


 

사용자 제거

drop user '{user_id}'@'localhost';

 

delete from user where user='{user_id}'@'localhost';

 


 

'공부 기록 > Database' 카테고리의 다른 글

DML - 데이터 조작하기  (0) 2023.01.19
DDL - Table 생성하기, 목록 및 구조 확인  (0) 2023.01.19
Database 생성, 접속하기  (0) 2023.01.19
RDBMS _ 관계형 데이터베이스  (0) 2023.01.18
Database 개론  (0) 2023.01.18