MYSQL

[MySql] 권한 주기

SojuMan 2010. 7. 4. 16:59

RANT문을 사용해 사용자를 추가하거나 권한을 부여할수도 있습니다.
GRANT ALL ON TO @ IDENTIFIED BY '비밀번호';


사용자 권한 삭제는 REVOKE문을 사용하시면 됩니다.
REVOKE ON FROM ;


1) user1에 모든 db의 권한을 줄때 ( root를 제외한 super user : dba )
localhost의 권한
grant all privileges on *.* to user1@localhost identified by 'pass1';

%의 권한
grant all privileges on *.* to user1 identified by 'pass1';

2) user1에 db1의 사용권한을 줄때
localhost의 권한
grant all privileges on db1.* to user1@localhost identified by 'pass1';

%의 권한
grant all privileges on db1.* to user1 identified by 'pass1';

3) user1에 db1의 tb1의 권한을 줄때
localhost의 권한
grant all privileges on db1.tb1 to user1@localhost identified by 'pass1';

%의 권한
grant all privileges on db1.tb1 to user1 identified by 'pass1';

권한 삭제는
REVOKE all on *.* from user1




출처 : http://msgzoro.egloos.com/3274111

허락없이 퍼왔습니다. 문제가 될시에는 삭제하도록 하겠습니다.


보통 기본설치만 한 상태면 localhost로만 접속이 가능하도록 설정이 되어있는데, 외부에서 접속이 가능하도록 설정을 바꿔보자.

여기서는 root계정을 예로 들어 설명한다.

1. mysql 접속 후 mysql database 선택
mysql> use mysql;


2. user 테이블 살펴보기
mysql> select host, user, password from user;


root 의 host 값들은 localhost, 127.0.0.1 등으로 기본 등록되어 있지만, 외부접속을 나타내는 값이 없다. 특정 아이피로 지정할 수도 있지만 여기선 % 기호로 어디서든 접속 가능하게 만든다.


3. 권한 설정
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root의 패스워드';
Query OK, 0 rows affected (0.03 sec)


4. 등록확인하기
mysql> select host, user, password from user;


root 계정의 host 필드에 % 가 등록되었는지 확인한다.


5. refrash (모든 변경 사항을 적용시키기)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
여기까지 간단한 과정을 통해서 mysql외부접속이 가능해진다.