• MySQL 数据库--权限管理


    权限管理

    1.创建账号

            创建本地账号

      create user 'luke'@'localhost' identified by '123'; #mysql -uluke -p123

      创建远程账号

      create user 'luke'@'192.168.31.10' identified by '123'; #mysql -uluke -p123  -h 服务端ip 

      (192.168.31.10是客户端的ip)

      create user 'luke'@'192.168.31.%' identified by '123'; #mysql -uluke -p123  -h 服务端ip 

      (luke用户能在192.168.31.0-255任意网段上登录,而不是特定某个ip)

      create user 'luke'@'%' identified by '123'; #mysql -uluke -p123  -h 服务端ip

      (luke能在所有的ip上登录)

    2.授权

    user:*.*   #表放行的权限,针对:所有数据,所有库下所有表,以及表下的所有字段,没有grat权限

    db :db1.*  #该表放行的权限,针对:某一数据库,该数据库下的所有表,以及表下的所有字段

    tables_priv:db1.t1 #该表放行的权限。针对:某一张表,以及该表下的所有字段

    columns_priv:id,name #该表放行的权限,针对:某一个字段

     

    查看用户权限:

      select * from mysql.userG  #查看某用户是否user表内,如果在说明有user权限

     1 *************************** 1. row ***************************
     2                   Host: localhost
     3                   User: root
     4               Password:
     5            Select_priv: Y
     6            Insert_priv: Y
     7            Update_priv: Y
     8            Delete_priv: Y
     9            Create_priv: Y
    10              Drop_priv: Y
    11            Reload_priv: Y
    12          Shutdown_priv: Y
    13           Process_priv: Y
    14              File_priv: Y
    15             Grant_priv: Y
    16        References_priv: Y
    17             Index_priv: Y
    18             Alter_priv: Y
    19           Show_db_priv: Y
    20             Super_priv: Y
    21  Create_tmp_table_priv: Y
    22       Lock_tables_priv: Y
    23           Execute_priv: Y
    24        Repl_slave_priv: Y
    25       Repl_client_priv: Y
    26       Create_view_priv: Y
    27         Show_view_priv: Y
    28    Create_routine_priv: Y
    29     Alter_routine_priv: Y
    30       Create_user_priv: Y
    31             Event_priv: Y
    32           Trigger_priv: Y
    33 Create_tablespace_priv: Y
    34               ssl_type:
    35             ssl_cipher:
    36            x509_issuer:
    37           x509_subject:
    38          max_questions: 0
    39            max_updates: 0
    40        max_connections: 0
    View Code

      select * from mysql.dbG #查看用户是否在db表内,查看该用户对哪些库有权限

       select * from mysql.tables_privG #查看用户的针对某一张表的权限

    select * from tables_priv where user='egon4'G #查看egon4用户针对表的所有字段的权限

    #针对所有库的授权:*.*

    grant select on *.* to 'egon1'@'localhost' identified by '123'; #只在user表中可以查到egon1用户的select权限被设置为Y

     #针对某一数据库:db1.*

    grant select on db1.* to 'egon2'@'%' identified by '123'; #只在db表中可以查到egon2用户的select权限被设置为Y

       #针对某一个表:db1.t1

      grant select on db1.t1 to 'egon3'@'%' identified by '123'; #只在tables_priv表中可以查到egon3用户的select权限

    #针对某一个字段:

    grant select (id,name),update (age) on db1.t3 to 'egon4'@'localhost' identified by '123';#可以在tables_priv和columns_priv中看到相应的权限

    #对id,name 有select权限,对age 有update权限

     1 mysql> select * from tables_priv where user='egon4'G
     2 *************************** 1. row ***************************
     3        Host: localhost
     4          Db: db1
     5        User: egon4
     6  Table_name: t3
     7     Grantor: root@localhost
     8   Timestamp: 0000-00-00 00:00:00
     9  Table_priv:
    10 Column_priv: Select,Update
    11 row in set (0.00 sec)
    12 
    13 mysql> select * from columns_priv where user='egon4'G
    14 *************************** 1. row ***************************
    15        Host: localhost
    16          Db: db1
    17        User: egon4
    18  Table_name: t3
    19 Column_name: id
    20   Timestamp: 0000-00-00 00:00:00
    21 Column_priv: Select
    22 *************************** 2. row ***************************
    23        Host: localhost
    24          Db: db1
    25        User: egon4
    26  Table_name: t3
    27 Column_name: name
    28   Timestamp: 0000-00-00 00:00:00
    29 Column_priv: Select
    30 *************************** 3. row ***************************
    31        Host: localhost
    32          Db: db1
    33        User: egon4
    34  Table_name: t3
    35 Column_name: age
    36   Timestamp: 0000-00-00 00:00:00
    37 Column_priv: Update
    38 rows in set (0.00 sec)
    View Code

    #删除权限

    revoke select on db1.* to 'alex'@'%';

     

  • 相关阅读:
    注册表设置开机启动
    Sql Server 行转列、列转行
    [转]JavaScript继承详解
    创建开机启动项快捷方式
    【转】IEnumerable与IEnumerator区别
    [转]winform缩放时,控制控件的比例
    【转】反射调用性能比较
    Unity Ioc 学习笔记1
    【转】深入探析c# Socket
    【转】BOOL和bool的区别
  • 原文地址:https://www.cnblogs.com/lukechenblogs/p/8810363.html
Copyright © 2020-2023  润新知