mysql8.0权限认证1

目录

 

一、mysql权限系统的介绍

二、mysql权限级别的介绍

 mysql权限详解

全局权限(*.*)

 针对数据库级别的权限(数据库.*)

 针对数据库对象级别的权限

 针对表字段的权限

 三、常用权限


一、mysql权限系统的介绍

  • 权限系统的作用是授予来自某个主机某个用户可以查询、插入、 修改、删除等数据库操作的权限。
  • 权限控制(授权与回收)的执行语句包括create user, grant, revoke。
  • 授权后的权限都会存放在MySQL的内部数据库中(数据库名叫 mysql),并在数据库启动之后把权限信息复制到内存中。
  • MySQL用户的认证信息不光包括用户名,还要包含连接发起的主 机(以下两个joe被认为不是同一个用户)

       SHOW GRANTS FOR ‘joe’@‘office.example.com’;   SHOW GRANTS FOR 'joe'@'home.example.com';

二、mysql权限级别的介绍

  • 权限级别
  • 全局性的管理权限,作用于整个MySQL实例级别。
  • 数据库级别的权限,作用于某个指定的数据库上或者所有的数据库上。
  • 数据库对象级别的权限,作用于指定的数据库对象上(表、视图等)或 者所有的数据库对象上
  •  权限存储在mysql库的user, db, tables_priv, columns_priv, and procs_priv这几个系统表中,待MySQL实例启动后就加载到内存中。

mysql>use mysql;

mysql>select user,host from mysql.user;

  • 查看mysql实例默认root用户的权限(来自localhost)

mysql>show grants for root@localhost;

  •  查看mysql实例默认mysql.sys用户的权限(来自localhost)

mysql> show grants for ‘mysql.sys’@localhost;

  •  创建用户create user

create user 'cdq'@'localhost' identified by '123456';

 

 新创建用户默认只有连接数据库的权限(可以理解为没有任何权限)

  •  用户授权
  • 授予所有权限all

        grant all privileges on *.* to cdq@localhost;  ( *.*  :第一个星代表哪些数据库,第二个星代表哪些对象)

  • 授予部分权限(此处为查看权限 select)

        grant select on *.* to cdq@localhost;

  •  查看用户在指定系统表中的权限

select * from mysql.user where user='cdq' and host='localhost';

select * from mysql.db where user='cdq' and host='localhost';

select * from mysql.table where user='cdq' and host='localhost';

select * from mysql.columns_priv where user='cdq' and host='localhost';

select * from mysql.procs_priv where user='cdq' and host='localhost';

  •  回收所有权限

revoke all privileges on *.* from cdq@localhost;

  •  mysql权限详解

  • 全局权限(*.*)

  • 授予所有权限all

        grant all privileges on *.* to cdq@localhost; 

  • 授予部分权限(此处为查看权限 select)

        grant select on *.* to cdq@localhost

        回收权限:revoke select on *.* from cdq@localhost; 

  •  针对数据库级别的权限(数据库.*)

  • 授予cdq@localhost 对 mysql数据库的查看权限:grant select on mysql.* to cdq@localhost

  •  回收权限:revoke select on mysql.* from cdq@localhost;

 

  •  针对数据库对象级别的权限

  • 授予cdq@localhost 对 mysql.user对象的查看权限:grant select on mysql.user to cdq@localhost

  • 权限回收:revoke select on mysql.user from cdq@localhost;

  •  针对表字段的权限

  •  授予cdq@localhost 对 mysql.user对象的user字段查看权限:grant select(user) on mysql.user to cdq@localhost;

  • 回收权限

  •  同时授予增删改查权限
  •  授予cdq@localhost 对 mysql数据库增删改查的权限:

  • 回收权限

 三、常用权限

 

 

 

 

发布了28 篇原创文章 · 获赞 5 · 访问量 1190

猜你喜欢

转载自blog.csdn.net/weixin_40391011/article/details/103947939