zoukankan      html  css  js  c++  java
  • mysql数据库用户权限设置

    设置用户权限:
    格式:
    grant 权限列表 on 数据库名.表名 to '用户名'@'来源地址' identified by '密码';

    * 权限列表:用于列出授权的各种数据库操作,通过逗号进行分割,如:select,insert,update等,all表示所有权限,可以执行任意操作。
    * 库名.表名:用于指定授权操作的数据库和表的名称,可以使用通配符(*)表示所有。
    * 用户名@来源地址:用于指定用户和允许访问的客户机地址;来源地址可以是IP地址,域名,%通配符表示所有。(但不能表示localhost)

    mysql通配符:
    * _:任意单个字符 192.168.200._
    * _:任意长度的任意字符 192.168.200.%

    案例:
    MariaDB [(none)]> create database student;
    Query OK, 1 row affected (0.01 sec)

    MariaDB [(none)]> use student
    Database changed
    MariaDB [student]> create table users (user_name char(20) not null, user_passwd char(50),primary key (user_name));
    Query OK, 0 rows affected (0.01 sec)

    MariaDB [student]> insert into users values ('zhangsan',password('111111')),('lisi',password('222222'));
    Query OK, 2 rows affected (0.01 sec)
    Records: 2 Duplicates: 0 Warnings: 0

    MariaDB [student]> select * from users;
    +-----------+-------------------------------------------+
    | user_name | user_passwd |
    +-----------+-------------------------------------------+
    | lisi | *A0C1808B1A47CECD5C161FEE647F5427F4EB6F98 |
    | zhangsan | *FD571203974BA9AFE270FE62151AE967ECA5E0AA |
    +-----------+-------------------------------------------+
    2 rows in set (0.00 sec)

    MariaDB [student]> grant select,insert on student.users to 'root'@'%' identified by '111222';
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [student]> flush privileges; //刷新授权表
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [student]> exit
    Bye


    查看用户权限:
    show grants;
    show grants for '用户名'@'来源地址';


    撤销用户权限:
    revoke 权限名 on 数据库名.表名 from '用户名'@'来源地址';

  • 相关阅读:
    bzoj1318[spoj 744] Longest Permutation
    bzoj2146 Construct
    bzoj2448 挖油
    bzoj3961[WF2011]Chips Challenge
    bzoj4152[AMPPZ2014] The Captain
    AtCoder Regular Contest 076E Coneected?
    Codeforces 748D Santa Claus and a Palindrome
    bzoj3572[HNOI2014]世界树
    SQL SERVER 字段统一补0方法
    SSRS运行report builder报错 的解决方案
  • 原文地址:https://www.cnblogs.com/lyqlyqlyq/p/11653240.html
Copyright © 2011-2022 走看看