MySQL 8.0权限认证(上)
create user hans@localhost identified by '123456';
grants all on *.* to 'hans'@'localhost';
show grants for hans@localhost;
revoke all on *.* from 'hans'@'localhost';
grants all on *.* to 'hans'@'192.168.1.%'
grants select on *.* to 'hans'@'192.168.1.%
grants insert,update,delete on *.* to 'hans'@'192.168.1.10%
create user 'app1'@'10.0.0.%' identified by '123456';
grant select,instert,update,delete on a1.* to 'app1'@'10.0.0.%';
grant select on a2.b2 to 'app1'@'10.0.0.%';
grant select(id) on a3.b3 to 'app1'@'10.0.0.%';
mysql> create database a1;
Query OK, 1 row affected (0.11 sec)
mysql> create database a2;
Query OK, 1 row affected (0.04 sec)
mysql> create database a3;
Query OK, 1 row affected (0.05 sec)
mysql> use a1;
Database changed
mysql> create table t1 (sid int,name varchar(10));
Query OK, 0 rows affected (0.10 sec)
mysql> use a2;
Database changed
mysql> create table b2 (sid int,name varchar(10));
Query OK, 0 rows affected (0.06 sec)
mysql> use a3;
Database changed
mysql> create table b3 (sid int,name varchar(10));
Query OK, 0 rows affected (0.41 sec)
mysql> create user 'app1'@'192.168.91.%' identified by '123456!';
Query OK, 0 rows affected (0.08 sec)
mysql> grant select,insert,update,delete on a1.* to 'app1'@'192.168.91.%';
Query OK, 0 rows affected (0.08 sec)
mysql> grant select on a2.b2 to 'app1'@'192.168.91.%';
Query OK, 0 rows affected (0.09 sec)
mysql> grant select(sid) on a3.b3 to 'app1'@'192.168.91.%';
Query OK, 0 rows affected (0.04 sec)
mysql> select * from mysql.db where user='app1' and host='192.168.91.%'\G;
*************************** 1. row ***************************
Host: 192.168.91.%
Db: a1
User: app1
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: N
Drop_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Execute_priv: N
Event_priv: N
Trigger_priv: N
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> select * from mysql.tables_priv where user='app1' and host='192.168.91.%'\G;
*************************** 1. row ***************************
Host: 192.168.91.%
Db: a2
User: app1
Table_name: b2
Grantor: root@localhost
Timestamp: 0000-00-00 00:00:00
Table_priv: Select
Column_priv:
*************************** 2. row ***************************
Host: 192.168.91.%
Db: a3
User: app1
Table_name: b3
Grantor: root@localhost
Timestamp: 0000-00-00 00:00:00
Table_priv:
Column_priv: Select
2 rows in set (0.00 sec)
ERROR:
No query specified
mysql> select * from mysql.columns_priv where user='app1' and host='192.168.91.%'\G;
*************************** 1. row ***************************
Host: 192.168.91.%
Db: a3
User: app1
Table_name: b3
Column_name: sid
Timestamp: 0000-00-00 00:00:00
Column_priv: Select
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show grants for 'app1'@'192.168.91.%'\G;
*************************** 1. row ***************************
Grants for app1@192.168.91.%: GRANT USAGE ON *.* TO `app1`@`192.168.91.%`
*************************** 2. row ***************************
Grants for app1@192.168.91.%: GRANT SELECT, INSERT, UPDATE, DELETE ON `a1`.* TO `app1`@`192.168.91.%`
*************************** 3. row ***************************
Grants for app1@192.168.91.%: GRANT SELECT ON `a2`.`b2` TO `app1`@`192.168.91.%`
*************************** 4. row ***************************
Grants for app1@192.168.91.%: GRANT SELECT (`sid`) ON `a3`.`b3` TO `app1`@`192.168.91.%`
4 rows in set (0.00 sec)
ERROR:
No query specified
[root@localhost ~]# mysql -u app1 -h192.168.91.128 -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| a1 |
| a2 |
| a3 |
| information_schema |
+--------------------+
4 rows in set (0.00 sec)
MySQL [(none)]> use a2;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [a2]> insert into a2 (sid,name) values (1,'xjp');
ERROR 1142 (42000): INSERT command denied to user 'app1'@'192.168.91.129' for table 'a2'
mysql> use a3;
Database changed
mysql> show tables;
+--------------+
| Tables_in_a3 |
+--------------+
| b3 |
+--------------+
1 row in set (0.00 sec)
mysql> insert into b3 (sid,name) values (1,'xjp');
Query OK, 1 row affected (0.07 sec)
mysql> insert into b3 (sid,name) values (2,'mzd');
Query OK, 1 row affected (0.01 sec)
mysql> select * from b3;
+------+------+
| sid | name |
+------+------+
| 1 | xjp |
| 2 | mzd |
+------+------+
2 rows in set (0.00 sec)
MySQL [(none)]> use a3;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [a3]> show tables;
+--------------+
| Tables_in_a3 |
+--------------+
| b3 |
+--------------+
1 row in set (0.00 sec)
MySQL [a3]> select * from b3;
ERROR 1142 (42000): SELECT command denied to user 'app1'@'192.168.91.129' for table 'b3'
MySQL [a3]> select name from b3;
ERROR 1143 (42000): SELECT command denied to user 'app1'@'192.168.91.129' for column 'name' in table 'b3'
MySQL [a3]> select sid from b3;
+------+
| sid |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
mysql> revoke select on a2.b2 from 'app1'@'192.168.91.%';
Query OK, 0 rows affected (0.07 sec)
那我们再看下权限
mysql> show grants for 'app1'@'192.168.91.%'\G;
*************************** 1. row ***************************
Grants for app1@192.168.91.%: GRANT USAGE ON *.* TO `app1`@`192.168.91.%`
*************************** 2. row ***************************
Grants for app1@192.168.91.%: GRANT SELECT, INSERT, UPDATE, DELETE ON `a1`.* TO `app1`@`192.168.91.%`
*************************** 3. row ***************************
Grants for app1@192.168.91.%: GRANT SELECT (`sid`) ON `a3`.`b3` TO `app1`@`192.168.91.%`
3 rows in set (0.00 sec)
ERROR:
No query specified
[root@localhost ~]# mysql -u app1 -h192.168.91.128 -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| a1 |
| a3 |
| information_schema |
+--------------------+
3 rows in set (0.00 sec)
MySQL [(none)]> use a2;
ERROR 1044 (42000): Access denied for user 'app1'@'192.168.91.%' to database 'a2'
MySQL 8.0权限认证(上)的更多相关文章
- MySQL 8.0权限认证(下)
MySQL 8.0权限认证(下) 一.设置MySQL用户资源限制 通过设置全局变量max_user_connections可以限制所有用户在同一时间连接MySQL实例的数量,但此参数无法对每个 ...
- MySQL 8.0有什么新功能
https://mysqlserverteam.com/whats-new-in-mysql-8-0-generally-available/ 我们自豪地宣布MySQL 8.0的一般可用性. 现在下载 ...
- CentOS 6.6 MySQL 8.0详细安装步骤
1.备份服务器上MySQL数据库 [root@localhost ] # mysqldump -h localhost -u root -proot --databases Surpass --rou ...
- asp.net权限认证:OWIN实现OAuth 2.0 之密码模式(Resource Owner Password Credential)
asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...
- asp.net权限认证:OWIN实现OAuth 2.0 之授权码模式(Authorization Code)
asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...
- asp.net权限认证:OWIN实现OAuth 2.0 之简化模式(Implicit)
asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...
- MySQL 8.0.14 新的密码认证方式和客户端链接
MySQL 8.0.14 新的密码认证方式和客户端链接 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. MySQL8.0在密码认证方式发生了改变,这也是有点小伙伴在MySQL创建 ...
- 阿里云CentOS自动备份MySql 8.0并上传至七牛云
本文主要介绍一下阿里云CentOS7下如何对MySql 8.0数据库进行自动备份,并使用.NET Core 将备份文件上传至七牛云存储上,并对整个过程所踩的坑加以记录. 环境.工具.准备工作 服务器: ...
- elasticsearch shield(5.0以下版本 权限认证)
elasticsearch 5.0以下的版本要用到权限控制的话需要使用shield.下载地址: https://www.elastic.co/downloads/shield5.0以上的版本则可以使用 ...
随机推荐
- webpack从零的实践(新手良药)
1. 什么是webpack? 本质上,webpack是一个现代javascript应用程序的静态模块打包器.webpack处理应用程序时,它会递归地构建一个依赖关系图(dependency graph ...
- Asp.net Core 3.1 Razor视图模版动态渲染PDF
Asp.net Core 3.1 Razor视图模版动态渲染PDF 前言 最近的线上项目受理回执接入了电子签章,老项目一直是html打印,但是接入的电子签章是仅仅对PDF电子签章,目前还没有Html电 ...
- ql的python学习之路-day11
前言:本节主要学习python内置的方法 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:qinjiaxi from collections ...
- React:Conditional Rendering(条件渲染)
就像JS中常常会根据条件(比如if/else.switch)返回不同的值,React中也可以根据组件的状态或其他参考条件返回不同的React Element. 比如根据用户是否登陆渲染对应的UI面板. ...
- STM32 HAL库学习系列---定时器TIM 输入捕获功能
基本方法 1.设置TIM2 CH1为输入捕获功能: 2.设置上升沿捕获: 3.使能TIM2 CH1捕获功能: 4.捕获到上升沿后,存入capture_buf[0],改为捕获下降沿: 5.捕获到下降沿后 ...
- 16-3 update语句
--打开和关闭查询窗口:ctrl+R --更新语句: --update 表名 set 列=新值,列2=新值2,... where 条件 --update语句,如果不加where条件,那么表示对表中所有 ...
- JPA EntityManager 在没有实体类的情况下返回Map
JPA entityManager.createNativeQuery()执行原生的SQL,当我们查询结果没有对应的实体类时,query.getResultList()返回的是一个List<Ob ...
- 【Java】几种典型的内存溢出案例,都在这儿了!
写在前面 作为程序员,多多少少都会遇到一些内存溢出的场景,如果你还没遇到,说明你工作的年限可能比较短,或者你根本就是个假程序员!哈哈,开个玩笑.今天,我们就以Java代码的方式来列举几个典型的内存溢出 ...
- centos 7 firewalld防火墙配置
1.查看firewall服务状态 systemctl status firewalld 2.查看firewall的状态 firewall-cmd --state 3.开启.重启.关闭.firewall ...
- js中 addEventListener 和removeEventListener
js中添加事件监听本来是非常常见的事情,但是去除监听一般很少去干,最近项目中需要监听页面显示或者隐藏 代码如下 document.addEventListener(visibilitychange', ...