MySQL用户管理

mysql 用户管理
    MYSQL 是一个tcp 服务器 用于操作服务器上的文件数据,
    接收用户端发送的指令, 接收指令时需要考虑安全问题
    是不是谁给我发我都要回应?

    atm 购物车中的用户认证和mysql的用户认证原理是一样的
    mysql中把文件称为表


    在mysql自带的mysql数据库中有4个表用于用户管理的
    分别是: 优先级从高到低
    user -> db -> tables_priv -> columns_priv


    1.创建用户的语句
        create user  用户名@"主机地址" identified by "密码";

        create user  scote@"127.0.0.1" identified by "123";
        此处的主机地址 不是服务器地址 而是表示 这个账户可以在那台电脑上登录

    2. 授权的语句  *******
        语法: grant [权限的名称 select insert.... | all ] on 数据库.表名  to 用户名@主机地址;
        # 授予 scote 这个用户所有权限 在所有数据库所有表中
        grant all on *.* to scote@"localhost"; 可以访问 所有库和表
        grant all on day41.* to scote@"localhost";  可以访问day41库的所有表
        grant all on day41.stu to scote@"localhost"; 可以访问day41库的stu表
        grant select(id,name),insert(id,name) on day41.stu to scote@"localhost";
                                                    仅能查看和添加 day41库的stu表中的 id和name字段


        grant all on mydb1.* to testDBA@"%"  identified by "123";


    3.grant [权限的名称 select insert.... | all ] on 数据库.表名  to 用户名@主机地址 with grant option;
        with grant option 这个用户可以将他有的权限授予别的账户
        特点: 如果授权时  用户不存在 直接自动创建用户

 

    4.删除权限
       revoke 权限的名称 on 数据库.表名  from 用户名@"主机名" ;
       revoke all on *.* from scote@"localhost";

       update mysql.user set  Grant_priv = "N" where user ="scote" and host = "localhost";

     *.刷新权限表
        flush privileges;

     5.删除用户
        drop user 用户名@"主机地址";

 

posted @ 2018-09-17 15:48  没有显示名称  阅读(120)  评论(0编辑  收藏  举报