zoukankan      html  css  js  c++  java
  • MySQL 数据库安全设计

    相关知识:

    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';
  • 相关阅读:
    存储过程
    Java抽象类与接口的区别
    Spring资源
    30分钟搞定后台登录界面(103个后台PSD源文件、素材网站)
    单例模式(Singleton)的同步锁synchronized
    常用快捷键大全
    设计模式学习总结(一)——设计原则与UML统一建模语言
    git命令
    Test测试方法
    oracle表分区
  • 原文地址:https://www.cnblogs.com/junfblog/p/12774245.html
Copyright © 2011-2022 走看看