//유저생성과 함께 한 접속지 주소에서 한 테이블에 권한부여
grant all privileges on 디비명.테이블명 to 유저명@’접속지 주소’ identified by ‘암호’;
//유저생성과 함께 외부에서 한 DB에 권한부여
grant all privileges on 디비명.* to 유저명@’%’ identified by ‘암호’; //%는 외부접근
//유저생성과 함께 내부에서 모든 DB에 권한부여
grant all privileges on *.* to 유저명@’localhost’ identified by ‘암호’; //localhost는 내부접근
//한 사용자의 DB 모든 권한 제거
revoke all on 디비명.* from 사용자;
//한 아이피에서 사용자의 테이블 권한 제거
revoke all privileges on 디비명.테이블명 from 사용자@아이피;
//권한 적용
모든 명령 후에 항상 아래 명령을 실행해야 실제로 적용된다.
flush privileges;
<샘플>
// ‘사용자’가 ‘암호’으로 111.222.333.xxx 에서 모든 디비와 테이블에 접속하도록 허용
grant all privileges on . to 사용자 @’111.222.333.%’ identified by ‘암호’;
// ‘사용자’가 ‘암호’으로 111.222.333.444 에서 db1 디비의 모든 테이블에 접속하도록 허용
grant all privileges on db1.* to 사용자@’111.222.333.444′ identified by ‘암호’;
// ‘사용자’가 ‘암호’으로 localhost 에서 db1 디비의 table1에 접속하도록 허용
grant all privileges on db1.table1 to 사용자@’localhost’ identified by ‘암호’;