Mysql 数据库的权限问题

之前一直对Mysql数据库的权限没太理解

root用户具有最高的权限,也就是超级用户,root用户可以看到数据库中的所有的内容,而其它用户只能对经过root用户授权过的数据库进行操作,如果想在其它用户中创建新的数据库       而对root用户不可见,是不行的,而将其它用户的权限设置成:

      grant all on *.* to 'my_user'@'localhost';

      这时,其它用户的权限相当于root 用户,没有实际意义。

      revoke all on *.* from 'my_user'@'localhost';//回收用户的权限

      grant all on db.* to 'my_user'@'localhost';//只授予对db数据库的操作权限

      grant select(stu_no) on db.stu to 'my_user'@'localhost';//只授予对db数据库的stu表的stu_no列的select权限   列级授权

      select * from mysql.user

      

     查看用户的权限,注:此时查看到的是全局权限,也就是对所有数据库的操作权限而:

       grant all on *.* to 'my_user'@'localhost';//授予的是数据库权限,全局权限>数据库权限,当全局权限不满足条件时再查看数据库权限

     修改全局权限:

     update mysql.user set Create_priv='Y' where user='my_user';此时会报错,因为mysql安全模式下非主键无法执行update和delete操作

     这时查看mysql.user 表:

     desc mysql.user

    

    这张表中host和user是组合主键,所以有两种修改方法:

    ①set sql_safe_updates=0;

    ②update mysql.user set Create_priv='Y where user='my_user' and host='localhost';

查看授予给指定用户的权限

show grants for 'my_user'@'localhost'

 

posted @ 2017-12-14 17:15  吾漫兮  阅读(7081)  评论(0编辑  收藏  举报