博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL视图已经授权,但是无法访问
阅读量:5273 次
发布时间:2019-06-14

本文共 4129 字,大约阅读时间需要 13 分钟。

开发发来问题说,开发环境的几个视图已经授权,但是指定用户登录后却无法访问。报错信息如下:

[SQL]select * from ipost;[Err] 1045 - Access denied for user 'iqm'@'%' (using password: YES)

正式环境可以正常访问。

 

一开始以为是权限没有给予正确。

查看正式的授权情况:

mysql> show grants for tiq\G*************************** 1. row ***************************Grants for tiq@%: GRANT USAGE ON *.* TO 'tiq'@'%'*************************** 2. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`iperson` TO 'tiq'@'%'*************************** 3. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`idept` TO 'tiq'@'%'*************************** 4. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`icomp` TO 'tiq'@'%'*************************** 5. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`ipost` TO 'tiq'@'%'5 rows in set (0.00 sec)mysql>

查看测试环境授权情况:

mysql> show grants for tiq\G*************************** 1. row ***************************Grants for tiq@%: GRANT USAGE ON *.* TO 'tiq'@'%'*************************** 2. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`idept` TO 'tiq'@'%'*************************** 3. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`icomp` TO 'tiq'@'%'*************************** 4. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`iperson` TO 'tiq'@'%'*************************** 5. row ***************************Grants for tiq@%: GRANT SELECT ON `tuc`.`ipost` TO 'tiq'@'%'5 rows in set (0.00 sec)mysql>

对比发现授权没有问题。

 

然后查看其中一个视图在正式、测试环境中的定义。

正式环境查看视图的定义:

mysql> show create view ipost\G*************************** 1. row ***************************                View: ipost         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`uadmin`@`%` SQL SECURITY DEFINER VIEW `ipost` AS select `t_post`.`id` AS `id`,`t_post`.`postcode` AS `postcode`,`t_post`.`postname` AS `postname`,`t_post`.`pk_job` AS `pk_job`,`t_post`.`job_code` AS `job_code`,`t_post`.`job_name` AS `job_name`,`t_post`.`org_code` AS `org_code`,`t_post`.`org_name` AS `org_name`,`t_post`.`pk_org` AS `pk_org`,`t_post`.`pk_post` AS `pk_post`,`t_post`.`status` AS `STATUS`,`t_post`.`enablestate` AS `enablestate`,`t_post`.`writebackoperate` AS `writebackoperate`,`t_post`.`writebackts` AS `writebackts`,`t_post`.`syncts` AS `syncts`,`t_post`.`operate` AS `operate`,`t_post`.`dirty` AS `dirty`,`t_post`.`ts` AS `ts`,`t_post`.`del_flag` AS `del_flag` from `t_post`character_set_client: utf8collation_connection: utf8_general_ci1 row in set (0.00 sec)mysql>

 

测试环境查看视图的定义:

mysql> show create view ipost\G*************************** 1. row ***************************                View: ipost         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`uadmin`@`%` SQL SECURITY DEFINER VIEW `ipost` AS select `t_post`.`id` AS `id`,`t_post`.`postcode` AS `postcode`,`t_post`.`postname` AS `postname`,`t_post`.`pk_job` AS `pk_job`,`t_post`.`job_code` AS `job_code`,`t_post`.`job_name` AS `job_name`,`t_post`.`org_code` AS `org_code`,`t_post`.`org_name` AS `org_name`,`t_post`.`pk_org` AS `pk_org`,`t_post`.`pk_post` AS `pk_post`,`t_post`.`status` AS `STATUS`,`t_post`.`enablestate` AS `enablestate`,`t_post`.`writebackoperate` AS `writebackoperate`,`t_post`.`writebackts` AS `writebackts`,`t_post`.`syncts` AS `syncts`,`t_post`.`operate` AS `operate`,`t_post`.`dirty` AS `dirty`,`t_post`.`ts` AS `ts`,`t_post`.`del_flag` AS `del_flag` from `t_post`character_set_client: utf8collation_connection: utf8_general_ci1 row in set, 1 warning (0.00 sec)mysql>

从这里可以发现,结果显示有个一个warning存在。

查看该warning的具体内容:

mysql> show warnings;+-------+------+--------------------------------------------------------------+| Level | Code | Message                                                      |+-------+------+--------------------------------------------------------------+| Note  | 1449 | The user specified as a definer ('uadmin'@'%') does not exist |+-------+------+--------------------------------------------------------------+1 row in set (0.00 sec)

从这里可以看出,视图创建的时候,将正式环境的用户带了过来,但是测试环境并不存在该用户。其实原因很简单,就开发从ide中直接从正式环境把定义语句导出后在测试环境执行了。

转载于:https://www.cnblogs.com/abclife/p/7233082.html

你可能感兴趣的文章
Leetcode Balanced Binary Tree
查看>>
[JS]递归对象或数组
查看>>
linux sed命令
查看>>
湖南多校对抗赛(2015.03.28) H SG Value
查看>>
hdu1255扫描线计算覆盖两次面积
查看>>
hdu1565 用搜索代替枚举找可能状态或者轮廓线解(较优),参考poj2411
查看>>
程序存储问题
查看>>
优雅地书写回调——Promise
查看>>
AX 2009 Grid控件下多选行
查看>>
PHP的配置
查看>>
Struts框架----进度1
查看>>
Round B APAC Test 2017
查看>>
MySQL 字符编码问题详细解释
查看>>
Ubuntu下面安装eclipse for c++
查看>>
Windows 2003全面优化
查看>>
格而知之2:UIView的autoresizingMask属性探究
查看>>
我的Hook学习笔记
查看>>
js中的try/catch
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
整理推荐的CSS属性书写顺序
查看>>