如何使用有限权限创建 MySQL 用户?


要使用有限的权限创建 MySQL 用户,以下是语法 −

CREATE USER 'yourUserName'@'yourHostName' IDENTIFIED BY 'yourPassword';

以下是设置用户权限限制的语法 −

GRANT SELECT, INSERT, UPDATE, etc. REFERENCES
ON yourDatabaseName.* TO 'yourUserName'@'yourHostName';

让我们实现上述语法,使用有限的权限创建一个 MySQL 用户 −

mysql> CREATE USER 'David'@'localhost' IDENTIFIED BY 'david';
Query OK, 0 rows affected (0.20 sec)
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, ALTER, CREATE, REFERENCES
   ON test.* TO 'David'@'localhost';
Query OK, 0 rows affected (0.21 sec)

让我们检查是否已经创建了用户名为“David”的用户。

mysql> select user, host from MySQL.user;

这将产生以下输出 −

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| Bob              | %         |
| User2            | %         |
| mysql.infoschema | %         |
| mysql.session    | %         |
| mysql.sys        | %         |
| root             | %         |
| @UserName@       | localhost |
| Adam Smith       | localhost |
| David            | localhost |
| James            | localhost |
| John             | localhost |
| John Doe         | localhost |
| User1            | localhost |
| am               | localhost |
| hbstudent        | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
+------------------+-----------+
17 rows in set (0.00 sec)

更新于:30-Jul-2019

443 次浏览

开始您的 职业生涯

通过完成课程获得认证

开始使用
广告