사용자

○ 사용자 로그인 (데이터베이스 서버접속)

$ mysql -u 사용자명 -p
Enter password: *************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.23 MySQL Community Server - GPL

 

- root 계정 로그인

$ mysql -u root -p

 

○ 사용자 생성, 비밀번호 변경, 삭제

-- 생성 --
CREATE USER 'scott' IDENTIFIED BY '1234';		-- user : scott / password : 1234
CREATE USER 'scott'@'localhost' IDENTIFIED BY '1234';	-- localhost : 내부접근만
CREATE USER 'scott'@'%' IDENTIFIED BY '1234';		-- % : 외부접근

-- 비밀번호 변경 --
# mysql 5.x버전
UPDATE USER SET password=PASSWORD('변경할 비밀번호') where user='scott';

# mysql 8.x버전
ALTER USER 'scott'@'localhost' identified with mysql_native_password by '변경할 비밀번호'

-- 삭제 --
DROP user scott;

→ @ 뒷부분은 host임

 

○ 사용자 확인

# mysql 5.x버전
SELECT host, user, password FROM user;

# mysql 8.x버전
SELECT host, user, authentication_string FROM user;

 

 

권한

grant all privileges on *.* to 'scott'@'%';
flush privileges;

→ 모든 DB의 모든 테이블에 모든 권한을 'scott' 에게 부여

grant select, insert, update on DBname.* to 'scott'@'%';
flush privileges;

→ DBname이라는 DB의 모든 테이블에 select, insert, update 권한을 'scott' 에게 부여

 

revoke all on DBname from 'scott';
flush privileges;

→ DBname이라는 DB의 모든 권한을 'scott'으로 부터 철회함

 

○ 권한 확인

show grants for 'scott'@'localhost';

'DB > Mysql' 카테고리의 다른 글

[Mysql] Database, Schema(데이터베이스, 스키마)  (0) 2021.02.12

+ Recent posts