dba가 되었다고 생각하고 마리아 db 계정 생성 및 권한부여를 한다.
다만 select 권한과 전체 권한 2개의 계정을 생성한다.
%일 경우는 서버 접속하여 localhost에서 안되기 때문에
서버 접속해서 sql 할 일이 있으니 localhost도 같이 만든다.
select 권한 만: testuser
전체권한 : testadm
testuser 계정생성(비번은 ID와 동일):
create user 'testuser'@'%' identified by 'testuser';
create user 'testuser'@'localhost' identified by 'testuser';
testadm 계정생성(비번은 ID와 동일):
create user 'testadm'@'%' identified by 'testadm';
create user 'testadm'@'localhost' identified by 'testadm';
testuser에 select 권한만 부여:
grant select on testdb.* to 'testuser'@'%';
grant select on testdb.* to 'testuser'@'localhost';
testadm에 전체 권한 부여:
grant all privileges on testdb.* to 'testadm'@'%';
grant all privileges on testdb.* to 'testadm'@'localhost';
잘 들어갔는지 확인
MariaDB [mysql]> show grants for 'testuser'@'%';
MariaDB [mysql]> show grants for 'testuser'@'%';
+-----------------------------------------------------------------------------------------------------------+
| Grants for testuser@% |
+-----------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `testuser`@`%` IDENTIFIED BY PASSWORD '*B045CE5ED8BCAB18BB9337381465D37D8xxxxxxx' |
| GRANT SELECT ON `testdb`.* TO `testuser`@`%` |
+-----------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
MariaDB [mysql]> show grants for 'testadm'@'%';
+----------------------------------------------------------------------------------------------------------+
| Grants for testadm@% |
+----------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `testadm`@`%` IDENTIFIED BY PASSWORD '*D5750A48D45703446E2B209F9946F8175xxxxxxx' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO `testadm`@`%` |
+----------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
mysql DB가 선택되고 show grants를 날려야 한다.
만약 선택 안되어 있으면
show databases;
use mysql 하고 show grants 하면 된다.
사용자가 로그인이 되어 있다면 로그아웃 하고 다시 로그인해야 위의 권한이 제대로 적용될 것이다.
flush privileges; 해도 되고..
testdb 를 만들고 testtable 만들어서 테스트 해보면 된다.
만약 insert 권한이 없는 사용자가 insert 하려고 하면 권한이 없다고 나올것이다.