ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

SQL_server 数据库安全设计

2020-04-25 18:03:32  阅读:341  来源: 互联网

标签:数据库安全 grant 数据库 identified server 订单 usercode1 SQL 权限


相关知识:

1、创建用户:

(1)创建名为user1的用户,密码为user1coder,只能在localhost登录。

CREATE USER  'user1'@'localhost' IDENTIFIED BY  'user1coder';

(2)创建名为user2,密码为123的用户,可以通过任何ip连接数据库。

create user 'user2'@'%' identified by '123'

(3)删除用户

DROP USER  'user1'@'localhost';

(4)查看用户

select user,host  from  mysql.user;

2、权限管理

  1. all 所有权限(不包括授权权限)
  2. Delete权限代表允许删除行数据的权限
  3. Insert权限代表是否允许在表里插入数据
  4. Select权限代表允许从表中查看数据,某些不查询表数据的select执行则不需要此权限,如Select 1+1, Select PI()+2;而且select权限在执行update/delete语句中含有where条件的情况下也是需要的
  5. Update权限代表允许修改表中的数据的权限
  6. Usage权限是创建一个用户之后的默认权限,其本身代表连接登录权限

(1)查看权限

show grants for 'user1'@'localhost' ;

(2)收回权限

  1. revoke 权限列表 on 对象列表 from 用户列表
  2. revoke all on mydb.* from 'user1'@'localhost'; //回收所有权限
  3. revoke select,delete on *.* from 'user1'@'%'; //回收部分权限

3、库名.表名

  1. *.* 所有数据库下的所有表
  2. 数据库.* 指定数据库下的所有表
  3. 数据库名称.表名称 指定数据库的指定表
  4. select(col1名称),insert(col1名称,col2名称) on mydb.mytable 只能对mydb.mytable第一列有读权限,第一第二列有插入权限

 

任务描述:

注:grant命令执行后如果数据库中没有对应的角色会自动创建(授权命令)

(1)数据库维护人员(1人):可对订单数据库进行任何操作。
账号名称:system_dbowner,允许任何ip通过此用户连接数据库,密码为usercode1

grant all on 订单数据库.* to 'system_dbowner'@'%' identified by 'usercode1';

 

(2)数据录入人员(2人):可对订单数据库中所有表进行插入、删除、更新操作,不能创建与修改表结构及其它授权等操作。

 

账号名称:datarecorder1, datarecorder2,允许任何ip通过此用户连接数据库,密码为usercode1

grant insert,delete,update,select on 订单数据库.* to 'datarecorder1'@'%' identified by 'usercode1';
grant insert,delete,update,select on 订单数据库.* to 'datarecorder2'@'%' identified by 'usercode1';

 

(3)订单管理人员(2人):能对订单数据库中的订单表和项目表进行插入、删除、更新操作,其它表仅能查询。不能创建与修改表结构及其它授权等操作。

账号名称:order_1,order_2,允许任何ip通过此用户连接数据库,密码为usercode1

grant select on 订单数据库.* to 'order_1'@'%' identified by 'usercode1';--授予查询所有表格的权限
grant insert,delete,update on 订单数据库.订单 to 'order_1'@'%' identified by 'usercode1';
grant insert,delete,update on 订单数据库.订货项目 to 'order_1'@'%' identified by 'usercode1';

grant select on 订单数据库.* to 'order_2'@'%' identified by 'usercode2';--授予查询所有表格的权限
grant insert,delete,update on 订单数据库.订单 to 'order_2'@'%' identified by 'usercode1';
grant insert,delete,update on 订单数据库.订货项目 to 'order_2'@'%' identified by 'usercode1';

 

(4)客户管理人员(2人):能对订单数据库中的代理商表和客户表进行插入、删除、更新,其它表仅能查询。不能创建与修改表结构及其它授权等操作。
账号名称:customer_1, customer_2,允许任何ip通过此用户连接数据库,密码为usercode1

grant select on 订单数据库.* to 'customer_1'@'%' identified by 'usercode1';--授予查询所有表格的权限
grant insert,delete,update on 订单数据库.代理商 to 'customer_1'@'%' identified by 'usercode1';
grant insert,delete,update on 订单数据库.客户 to 'customer_1'@'%' identified by 'usercode1';

grant select on 订单数据库.* to 'customer_2'@'%' identified by 'usercode1';--授予查询所有表格的权限
grant insert,delete,update on 订单数据库.客户 to 'customer_2'@'%' identified by 'usercode1';
grant insert,delete,update on 订单数据库.代理商 to 'customer_2'@'%' identified by 'usercode1';

 

标签:数据库安全,grant,数据库,identified,server,订单,usercode1,SQL,权限
来源: https://www.cnblogs.com/junfblog/p/12774245.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有