美文网首页
MySql 5.7+【创建新用户】以及【授权】

MySql 5.7+【创建新用户】以及【授权】

作者: 黑铁大魔王 | 来源:发表于2020-06-11 11:51 被阅读0次

    首先:切换到mysql库

    use mysql;
    

    添加用户

    //允许指定ip连接
    create user '用户名'@'localhost' identified by '密码';
    
    //允许所有ip连接(%表示所有ip)
    create user 'demo'@'%' identified by 'demo';
    

    授权

    grant all privileges on 数据库名.表名 to '用户名'@'指定ip' identified by '密码' ;
    
    // *表示所有
    grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;
    

    设置操作权限

    // 设置所有权限
    grant all privileges on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;
    
    // 设置select权限
    grant select on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;
    
    // 其他权限: select, insert, delete, update用都好隔开
    grant select,insert on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;
    
    // 取消用户select权限
    REVOKE select ON what FROM '用户名';
    

    删除用户

    DROP USER username@localhost;
    

    修改后刷新

    FLUSH PRIVILEGES;
    

    全套操作:

    use mysql;
    create user 'demo'@'%' identified by 'demo';
    grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;
    grant all privileges on *.* to 'demo'@'%' identified by 'demo' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    

    相关文章

      网友评论

          本文标题:MySql 5.7+【创建新用户】以及【授权】

          本文链接:https://www.haomeiwen.com/subject/boxbtktx.html