grant授权“失败”的原因
在创建用户的时候我们通常采用grant命令完成,并同时赋予相应的权限,例如我们创建一个名为test的用户,g并赋予其对数据库foo下所有表格select,delete,drop,create权限:
grant select,delete,drop,create on foo.* to test@localhost identified by 'test';
随后通过网上了解到的用户权限查看方式,有两种
1. mysql> show grants for test@localhost;
2. mysql> select * from user where user='test' \G
首先我们试着采用:
mysql> show grants for test@localhost;
+---------------------------------------------------------------------+
| Grants for test@localhost |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' |
| GRANT SELECT, DELETE, CREATE, DROP ON `foo`.* TO 'test'@'localhost' |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
结果上很容易理解,结果与我们的预期一致。
然后我们再试试另一种方式:
mysql> select * from user where user='test' \G
查看,输出结果如下:
*************************** 1. row ***************************
Host: localhost
User: test
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
password_expired: N
password_last_changed: 2016-11-30 13:10:01
password_lifetime: NULL
account_locked: N
1 row in set (0.00 sec)
如果在\G后加了一个分号结束语句该语句,那么将会在执行结果的最后有no query specified这个一个错误。\G 后不需要加分号。 |
那么问题来了,为什么两种查看用户权限的方式给出的结果不一样?而且在创建用户时明明赋予了select,delete,drop,create
权限但是第二种方法给出的结果中相应项都被标注为‘N'?是不是用grant命令给用户赋予权限失败了呢?应该以哪个结果为准呢?
究其原因是:select * from user where user='test' \G;给出的是全局的权限,而不是针对某个DB或者SCHEMA得权限。赋权
语句是grant select,delete,drop,create on foo.* to test@localhost identified by 'test';也就是针对foo这个数据库赋权。那么
自然会得出权限为‘N’的结果。那所创建 的用户是否具有我预期指定的对数据库foo的操作权限呢?
我们再新建另一个用户test2,这次我们只给该用户赋予create权限
mysql> grant create on foo.* to test2@localhost identified by 'test2';
使用mysql> select * from user where user='test2' \G 查看权限时所有权限妥妥的都是N.
我们先后使用test和test2登录mysql服务器。
1.test
root@deamon-H55M-S2:/etc/init.d# mysql -u test -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use foo;
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> show tables;
+---------------+
| Tables_in_foo |
+---------------+
| children |
| runoob_tbl |
| tcount_tbl |
+---------------+
3 rows in set (0.00 sec) mysql> select childno from children;
+---------+
| childno |
+---------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+---------+
8 rows in set (0.00 sec) 2.test2
oot@deamon-H55M-S2:/etc/init.d# mysql -u test2 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use foo;
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> select childno from children;
ERROR 1142 (42000): SELECT command denied to user 'test2'@'localhost' for table 'children'
mysql>
从结果中可以看出test select操作成功了,但是test2的select操作被拒绝了,这跟我们未给test2用户赋予select权限相符。
结论:
mysql> select * from user where user='test' \G方式查看的是全局权限,结果中的N不代表我们的赋权失败了。如果将创建语句改为
grant create on *.* to test2@localhost identified by 'test';那么结果就会都是’Y‘了。
两种查看用户权限的方式都没有错误,只是所代表的权限意义略有不同。show grants for test@localhost;方式能给我们更准确权限情况。
附文章深入学习MySQL授权表一篇:http://tech.it168.com/a2010/0114/837/000000837456.shtml
grant授权“失败”的原因的更多相关文章
- Autodesk Vault: 获取授权失败
在登录Vault Explorer时弹出对话框,获取授权失败,不能登录. 1.首先Autodesk Vault Professional采用网络版授权方式,在安装之前之前你需要首先配置网络授权服务器, ...
- 在ASP.NET中基于Owin OAuth使用Client Credentials Grant授权发放Token
OAuth真是一个复杂的东东,即使你把OAuth规范倒背如流,在具体实现时也会无从下手.因此,Microsoft.Owin.Security.OAuth应运而生(它的实现代码在Katana项目中),帮 ...
- "检索COM类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005" 问题的解决
一.故障环境 Windows 2008 .net 3.0 二.故障描述 调用excel组件生成excel文档时页面报错.报错内容一大串,核心是"检索COM类工厂中 CLSID为 {000 ...
- 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005
检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005 在CSDN上总是有网友问这个 ...
- 解决Office互操作错误"检索COML类工厂中 CLSID为 {xxx}的组件时失败,原因是出现以下错误: 80070005"
Excel为例(其他如Word也适用)文件数据导入时报出以下错误: 检索COML类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是 ...
- 此操作失败的原因是对 IID 为“{000208DA-0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface
有些电脑报错,有些电脑正常. 环境:VS2010 WinForm程序, Office2007 C#操作Excel时报错.错误: 无法将类型为“System.__ComObject”的 COM 对象强制 ...
- 检索 COM 类工厂中 CLSID 为 {820280E0-8ADA-4582-A1D9-960A83CE8BB5} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
检索 COM 类工厂中 CLSID 为 {820280E0-8ADA-4582-A1D9-960A83CE8BB5} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRE ...
- 【原创】asp.net导出word 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a
我的服务器:windows server 2008(64位)+microsoft office 2007 企业版 业务:网站导出应聘word简历. 出现以下错误: 检索 COM 类工厂中 CLSID ...
- C#操作word或excel及水晶报表,检索 COM 类工厂中 CLSID 为 {} 的组件时失败,原因是出现以下错误: 80070005
解决办法一:<转自http://www.cnblogs.com/Sue_/articles/2123372.html> 具体解决方法如下: 1:在服务器上安装office的Excel软件. ...
随机推荐
- iOS OC语言: Block底层实现原理 (转载)
作者:Liwjing 地址:http://www.jianshu.com/users/8df89a9d8380/latest_articles 先来简单介绍一下Block Block是什么? 苹果推荐 ...
- cocos2d-x RenderTexture
转自:http://blog.csdn.net/bill_man/article/details/7250911 1.CCRenderTexture 使用CCRenderTexture的过程总结起来一 ...
- Codeforces Round #268 (Div. 1) A. 24 Game 构造
A. 24 Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/A D ...
- VBScript
VBScript then PrintWMIErrorthenExit Err.Description, Err.Number else ifnot boolCathiMode then wscrip ...
- 五、Socket之UDP异步传输文件-实现传输中取消传送
上一篇文章四.Socket之UDP异步传输文件中,只实现了传输开始前拒绝接收文件,没有实现文件传输进行的时候取消传送,这篇文章中我们就来介绍怎样实现这个功能. 在传输过程中取消文件的传送,有很多地方要 ...
- Mysql-5.6乱码问题
1 参考:http://www.testwo.com/blog/6930 mysql数据库默认的编码是:Latin1,要想支持中文需要修改为gbk/utf8的编码格式. 1.以root管理员身份查 ...
- 转--object-C 与lua使用wax交互
[51CTO独家译文]2011年6月的编程语言排行榜Lua语言一军突起,一举进入前十名.这与一年前苹果决定在iOS系统上使用Lua语言密不可分.但是,你了解如何用Lua语言在iOS上开发应用吗?51C ...
- Java 开源分布式缓存框架Ehcache
http://www.codeceo.com/article/java-ehcache.html
- ORM之PetaPoco入门(一)--Petapoco简介
1. ORM概括 1.1. ORM简介 ORM 对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发展而产生的.面向对象的开发方法是当今企业级应 ...
- JavaScript学习总结一(String对象的用法)
javascript String对象的常用API 1:indexOf indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置.如果没有找到匹配的字符串则返回 -1.注意: inde ...