MySQL view definer permissions and error 1356

只谈情不闲聊 提交于 2019-12-25 09:05:39

问题


Background

I have a MySQL table G.devTest that looks like this:

+----+------+
| id | j    |
+----+------+
|  1 |    5 |
|  2 |    9 |
|  3 |    4 |
|  4 |    7 |
+----+------+

Logged in as my user l, I can create and select from a simple view based on this table without problems:

> create view devTestV as select * from devTest;
Query OK, 0 rows affected (0.02 sec)
> select * from devTestV;
+----+------+
| id | j    |
...

The Problem

I want to use this view based only on devTest:

> create view devTestV2 as select a.id, a.j, b.avg from devTest a cross 
join (select avg(j) avg from devTest) b;

That first appears to work fine, but when I try to select from it, things go awry:

> select * from devTestV2;
ERROR 1356 (HY000): View 'G.devTestV2' references invalid table(s) 
or column(s) or function(s) or definer/invoker of view lack rights to use 
them

Analysis

We know devTest exists, as do its columns id and j, so the "definer/invoker" part of the error must be the relevant one. My user l, the definer of the view (which by default uses the definer's permissions) must lack some permission. This conclusion is corroborated by the fact that the same view is accessible when created by the root user.

However, my user has all permissions for all objects in the G database:

> show grants;
...
| GRANT ALL PRIVILEGES ON `G`.* TO 'l'@'%'
...

What, then, does my user lack that prevents it from selecting from devTestV2?


回答1:


Instead of "create view..." try "create SQL SECURITY INVOKER view..." I was having the same problem until I made this change.



来源:https://stackoverflow.com/questions/43291779/mysql-view-definer-permissions-and-error-1356

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!