Database
원본 글 보기

[MySQL] 사용자 관리 명령어: 조회, 생성, 삭제, 권한 부여, 비밀번호 변경

[MySQL] 사용자 관리 명령어: 조회, 생성, 삭제, 권한 부여, 비밀번호 변경

Mysql 사용자 조회



use mysql;
select user, host from user;

Mysql 사용자 추가/생성

(사용자 생성/추가를 위해 mysql에 root로 접속.)



 mysql -u root -p mysql

# create user를 이용한 사용자 생성/추가



# 사용자 생성
create user 'USER_ID'@'localhost' identified by 'USER_PASSWORD';

# 사용자 생성 예시
create user 'test'@'localhost' identified by 'test1234';
==================================================================

# 사용자 권한
grant all privileges on DATABASE_NAME.* to USER_ID@'localhost';

# 예시
grant all privileges on test_database.* to test@'localhost';

# grant를 이용한 사용자 추가



grant all privileges on DATABASE_NAME.* to USER_ID@'localhost' identified by 'USER_PASSWORD';

# 예시
grant all privileges on test_database.* to test_grant@'localhost' identified by 'test1234';

# 'localhost' 대신 '%' 을 사용할 경우 외부에서도 접속 가능



grant all privileges on DATABASE_NAME.* to USER_ID@'%' identified by 'USER_PASSWORD';

# 예시
grant all privileges on test_database.* to test_grant@'%' identified by 'test1234';

# 비밀번호 변경



use mysql; Database changed mysql> update user set password=PASSWORD('변경할 비밀번호');
where user='사용자이름';
flush privileges;

Mysql 사용자 삭제



delete from user where user='USER_ID';
flush privileges;
delete from user where user='test';