当前位置:Gxlcms > 数据库问题 > MySQL数据库用户、角色、授权

MySQL数据库用户、角色、授权

时间:2021-07-01 10:21:17 帮助过:13人阅读

1. 添加用户

insert into mysql.user(host,user,password) values(%, xiaoming, password(xiaoming123));

现在可以使用帐号(xiaoming,xiaoming123)登录MySQL了。但是只有默认权限,仅能操作两个数据库,information_schema和test

2. 授权

grant <权限列表> on <关系> to <用户/角色>

grant insert on school.* to xiaoming

此时,用户xiaoming就拥有了对数据库school的insert权限。

mysql> show databases; ---授权前
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)

mysql> show databases; --- 授权后
+--------------------+
| Database           |
+--------------------+
| information_schema |
| school             |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> use school;
Database changed
mysql> insert into student(name,score) values(xiaoming,60);
Query OK, 1 row affected (0.08 sec)

mysql> select * from student;
ERROR 1142 (42000): SELECT command denied to user xiaoming@10.0.2.2 for table student

 

3. 添加用户和授权

grant <权限> on <关系> to ‘<用户>‘@‘<主机>‘ identified by ‘<密码>‘

mysql> grant select on school.* to xiaoqiang@% identified by xiaoqiang123;

添加一个新用户并授权

 

4. 创建角色 

 

MySQL数据库用户、角色、授权

标签:授权   log   grant   form   l数据库   erro   bsp   set   ide   

人气教程排行