1、创建新用户

  通过root用户登录之后创建

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  创建新用户,用户名为testuser,密码为123456 ;

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,可以在本地访问mysql

  >> grant all privileges on *.* to testuser@"%" identified by "123456" ;   //  设置用户testuser,可以在远程访问mysql

  >> flush privileges ;  //  mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

  

  2、设置用户访问数据库权限

  >> grant all privileges on test_db.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,只能访问数据库test_db,其他数据库均不能访问 ;

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,可以访问mysql上的所有数据库 ;

  >> grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;  //  设置用户testuser,只能访问数据库test_db的表user_infor,数据库中的其他表均不能访问 ;

  

  3、设置用户操作权限

  >> grant all privileges on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;  //设置用户testuser,拥有所有的操作权限,也就是管理员 ;

  >> grant select on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;  //设置用户testuser,只拥有【查询】操作权限 ;

  >> grant select,insert on *.* to testuser@localhost identified by "123456"  ;  //设置用户testuser,只拥有【查询\插入】操作权限 ;

  >> grant select,insert,update,delete on *.* to testuser@localhost identified by "123456"  ;  //设置用户testuser,只拥有【查询\插入】操作权限 ;

  >> revoke select,insert ON what FROM testuser  //取消用户testuser的【查询\插入】操作权限 ;

  

  4、设置用户远程访问权限

  >> grant all privileges on *.* to testuser@“192.168.1.100” identified by "123456" ;  //设置用户testuser,只能在客户端IP为192.168.1.100上才能远程访问mysql ;

  

  5、关于root用户的访问设置

  设置所有用户可以远程访问mysql,修改my.cnf配置文件,将bind-address = 127.0.0.1前面加“#”注释掉,这样就可以允许其他机器远程访问本机mysql了;

  >> grant all privileges on *.* to root@"%" identified by "123456" ;   //  设置用户root,可以在远程访问mysql

  >> select host,user from user;   //查询mysql中所有用户权限

  关闭root用户远程访问权限

  >> delete from user where user="root" and host="%" ;  //禁止root用户在远程机器上访问mysql

  >> flush privileges ;  //修改权限之后,刷新MySQL的系统权限相关表方可生效  

MySQL分配角色权限的更多相关文章

  1. [.Net MVC] 用户角色权限管理_使用CLK.AspNet.Identity

    项目:后台管理平台 意义:一个完整的管理平台需要提供用户注册.登录等功能,以及认证和授权功能. 一.为何使用CLK.AspNet.Identity 首先简要说明所采取的权限控制方式.这里采用了基于角色 ...

  2. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(26)-权限管理系统-分配角色给用户

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(26)-权限管理系统-分配角色给用户 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x ...

  3. RABC权限控制(页面操作角色,权限和进行分配)

    上一节主要说的是如何通过url进行权限控制,这一节就说一下如何开发一个权限控制的界面,这样我们就能很方便的创建角色,并分配给用户不同角色和不同权限. 1.编写角色管理页面 这个编写较为简单,主要是通过 ...

  4. mysql授权、删除用户和角色权限

    备份权限 GRANT USAGE ON *.* TO 'backup'@'172.16.0.157' IDENTIFIED BY PASSWORD '*38B4F16EADB1601E713D9F03 ...

  5. ASP.NET MVC 通用角色权限管理系统

    RightControl 介绍 .NET 通用后台角色权限管理系统,已完成.项目地址:http://106.14.77.184/Admin/Login 码云地址:https://gitee.com/L ...

  6. MongoDB 的用户和角色权限

    副本和分片集群的安全设置参考这个:高级:https://files.cnblogs.com/files/sanduzxcvbnm/mongodb_advance.pdf 默认情况下,MongoDB实例 ...

  7. ASP.NET MVC5+EF6+EasyUI 后台管理系统-分配角色给用户

    系列目录 由于之前做了将权限赋给角色,还需要做将角色组赋给用户,和将用户赋给角色组,一个用户可以拥有多个角色组,一个角色组包含多个用户,打开模块管理,添加一个分配的操作码 并在 角色权限设置授权给他 ...

  8. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理8

    接下来做的是对页面的增删改查与页面与页面按钮之间的联系.先上代码和页面效果 using AuthorDesign.Web.App_Start.Common; using System; using S ...

  9. [转]扩展RBAC用户角色权限设计方案

    原文地址:http://www.iteye.com/topic/930648 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地 ...

随机推荐

  1. 使用js进行string和json之间转换的方法

    在数据传输过种中,json是以文本,即字符串的形式传递,字符串形似Json对象: var str1 = '{ "name": "Amy", "sex& ...

  2. BufferedReader类

    BufferedReader类用于从缓冲区中读取内容,多有的输入字节数据都将放在缓冲区中. BufferedReader中定义的构造方法只能接收字符输入流的实例,所以必须使用字符输入流和字节输入流的转 ...

  3. JavaScript排序算法——快速排序

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. HTML学习笔记——图片显示、图片跳转、图片相对路径

    1>显示图片.用a标签实现点击图片跳转.地图标签/点击图片上固定区域跳转 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...

  5. Ad-Hoc命令不熟悉的选项

    -f #并发线程数,默认5个线程 --private-key #指定秘钥文件 -k #--ask-pass SSH:认证密码 -K, #--ask-sudo-pass sudo:用户的密码(--sud ...

  6. Java VM for IOS

    http://oss.readytalk.com/avian/ http://robovm.com/ http://www.xmlvm.org/overview/

  7. Unity逻辑热更新

    http://www.xuanyusong.com/archives/3075 http://www.unitymanual.com/thread-36503-1-1.html http://www. ...

  8. thinkphp查询

    public function index(){ $result = M('content')->select() $this->assig('result',$result); $thi ...

  9. Why is applicationhost.config still being added to source control even thought it's in gitignore

      Why is applicationhost.config still being added to source control even thought it's in gitignore g ...

  10. authorization配置

    在 Web.config 文件的<configuration>标记的子标记<authorization>和</authorization>之间用于设置应用程序的授权 ...