MySQL 查询以创建用户和授权许可


要创建用户并授权许可,语法如下 −

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)

更新日期:31-12-2019

359次浏览

开启你的 职业生涯

完成课程后获得认证

开始
广告