사용자를 생성하고 권한을 부여하기 위한 구문은 다음과 같습니다 -
create database yourDatabaseName DEFAULT CHARACTER SET utf8; create user `yourUserName` identified by yourPassword; GRANT SELECT ON yourDatabaseName .* TO `yourUserName`; GRANT INSERT ON yourDatabaseName .* TO `yourUserName`; GRANT UPDATE ON yourDatabaseName .* TO `yourUserName`; GRANT DELETE ON yourDatabaseName .* TO `yourUserName`; GRANT EXECUTE ON yourDatabaseName .* TO `yourUserName`;
다음은 사용자를 생성하고 권한을 부여하는 쿼리입니다 -
mysql> create database demo_app DEFAULT CHARACTER SET utf8; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> create user `John_123` identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT SELECT ON demo.* TO `John_123`; Query OK, 0 rows affected (0.00 sec) mysql> GRANT INSERT ON demo.* TO `John_123`; Query OK, 0 rows affected (0.00 sec) mysql> GRANT UPDATE ON demo.* TO `John_123`; Query OK, 0 rows affected (0.00 sec) mysql> GRANT DELETE ON demo.* TO `John_123`; Query OK, 0 rows affected (0.00 sec) mysql> GRANT EXECUTE ON demo.* TO `John_123`; Query OK, 0 rows affected (0.00 sec)
위 사용자의 모든 권한을 표시해 보겠습니다.
mysql> show grants for `John_123`;
이것은 다음과 같은 출력을 생성합니다 -
+-----------------------------------------------------------------------------+ | Grants for John_123@% | +-----------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO `John_123`@`%` | | GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `demo`.* TO `John_123`@`%` | +-----------------------------------------------------------------------------+ 2 rows in set (0.00 sec)