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以上的版本则可以使用 ...
随机推荐
- Java常用设计模式详解1--单例模式
单例模式:指一个类有且仅有一个实例 由于单例模式只允许有一个实例,所以单例类就不可通过new来创建,而所有对象都默认有一个无参的构造函数可以创建对象,所以单例类不仅不能提供public的构造方法,还需 ...
- Python之日志处理(logging模块二实战)
实战篇 import logging import logging.handlers LOG_PATH = r'./' def logConfig_1(): ''' 配置 log 输出到文件 : fi ...
- 100道MySQL数据库经典面试题解析(收藏版)
前言 100道MySQL数据库经典面试题解析,已经上传github啦 https://github.com/whx123/JavaHome/tree/master/Java面试题集结号 公众号:捡田螺 ...
- SQL——SQL约束
SQL约束 - 用于限制加入表的数据的类型 可以在创建表时规定约束(通过 CREATE TABLE 语句),或者在表创建之后也可以(通过 ALTER TABLE 语句). NOT NULL ...
- Linux赋权chmod
chmod -R 777 文件名/ 给文件可读.可修改.可执行权限
- SPL常用函数
使用SPL_AUTOLOAD_REGISTER装载类 <?php /** * libs/Test.class.php */ class Test { function __construct() ...
- Unity设置应用后台运行
- 第4章 最基础的分类算法-k近邻算法
思想极度简单 应用数学知识少 效果好(缺点?) 可以解释机器学习算法使用过程中的很多细节问题 更完整的刻画机器学习应用的流程 distances = [] for x_train in X_train ...
- 添加nginx新模块,获取客户真实ip
当前是客户端登录软件后台获取不到客户的真实ip而是云盾的代理ip 为了获取到真实ip后来发现通过配置nginx的read_ip模块就可以了 获取客户的真实ip使用Nginx的realip模块 当Ngi ...
- 附件2:async/await
在实际开发中总会遇到许多异步的问题,最常见的场景便是接口请求之后一定要等一段时间才能得到结果,如果遇到多个接口前后依赖,那么问题就变得复杂.大家都一直在尝试使用更好的方案来解决这些问题.最开始只能利用 ...