首页 > 数据库 > MySQL > 正文

Mysql下建立用_户授权权限例子

2019-11-02 14:28:26
字体:
来源:转载
供稿:网友
用户授权在mysql中使用grant命令就可以了,我相信各位都会有了解过了,下面小编为各位介绍一个Mysql下建立用户授权权限例子,希望本文章对各位有帮助.  


建立用户,授权数据库:

mysql> create user 'byrd'@'localhost' identified by 'admin123';    #建立主机为localhost,密码为admin123的用户byrd
Query OK, 0 rows affected (0.05 sec)
mysql> show grants for 'byrd'@'localhost';    #查看byrd权限,USAGE表示连接权限
+-------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'byrd'@'localhost' IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |
+-------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | lamp      |
| byrd | localhost |
| root | localhost |
+------+-----------+
5 rows in set (0.00 sec)
mysql> grant all on gbk.* to 'byrd'@'localhost';    #用户byrd、主机localhost对数据库gbk拥有所有权限
Query OK, 0 rows affected (0.01 sec)

mysql> show mysqls for 'byrd'@'localhost';
+-------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'byrd'@'localhost' IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |
| GRANT ALL PRIVILEGES ON `gbk`.* TO 'byrd'@'localhost'                                                       |

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表