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

猜你喜欢

转载自www.cnblogs.com/lyqlyqlyq/p/11653240.html