您的位置:首页 > 数据库 > MySQL

MySQL:增加用户以及赋予不同的权限

2016-08-04 11:47 423 查看
在一个服务器上有多个数据库或者多个项目的时候,我们希望,每个项目的人,能否访问它的数据,而且对外提供服务的时候,如果也希望,尽量的安全考虑,尽量的只给需要的权限。

所以,我们打算给,每一个项目,它需要的最恰当的权限,来创建多个用户。

一.创建用户
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';


创建的 jeffrey 用户可以在 mysql里面的mysql数据库,对应的user里面查到

我们在下面运行

mysql> select User from user where User = 'jeffrey';

+---------+

| User    |

+---------+

| jeffrey |

+---------+

1 row in set (0.00 sec)

二.给刚才创建的用户给权限
MySQL 赋予用户权限命令的简单格式可概括为:


grant
权限 on 数据库对象
to 用户

GRANT ALL ON db1.* TO 'jeffrey'@'localhost';


给jeffrey对db1数据库的所有数据操作权限

一、grant
普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利

grant
select
on db1.*
to 'jeffrey'@'%'
grant
insert
on

db1.*
to 'jeffrey'@'localhost'
grant
update
on

db1.*
to

'jeffrey'@'localho
4000
st'
grant
delete
on

db1.*
to

'jeffrey'@'localhost'

二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。

grant 创建、修改、删除 MySQL 数据表结构权限。
grant create on testdb.* to developer@'192.168.0.%';
grant alter  on testdb.* to developer@'192.168.0.%';
grant drop  on testdb.* to developer@'192.168.0.%';

三、grant 高级 DBA 管理 MySQL 中所有数据库的权限。
grant all on *db1.* to jeffrey@'localhost'

参考
http://dev.mysql.com/doc/refman/5.6/en/grant.html http://www.cnblogs.com/hcbin/archive/2010/04/23/1718379.html
获取更多的文章,欢迎关注微信公众号

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  grant