신규 DB 생성 및 생성한 DB 사용자 추가 샘플코드

 

Root 계정으로 DB 접속하는 과정은 생략합니다.

 

// DB 생성
MariaDB [(none)]> CREATE DATABASE `[NEW_DB_NAME]` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

// User 생성 - localhost
MariaDB [(none)]> create user '[NEW_DB_USER]'@'localhost' identified by '[NEW_DB_USER_PW]';

// User 비밀번호 변경 - localhost
alter user '[TARGET_DB_USER]'@'localhost' identified by '[NEW_DB_PW]'; 

// User 생성 - connect any where
MariaDB [(none)]> create user '[NEW_DB_USER]'@'%' identified by '[NEW_DB_USER_PW]';

// 권한 부여
MariaDB [(none)]> grant all privileges on [TARGET_DB_NAME].* to '[TARGET_DB_USER]'@'%';

// 권한 삭제
MariaDB [(none)]> revoke all privileges on [TARGET_DB_NAME].* to '[TARGET_DB_USER]'@'%';

// 권한 확인
MariaDB [(none)]> show grants for '[TARGET_DB_USER]'@'%';

// 권한 변경 사항 반영
MariaDB [(none)]> flush privileges;