mysql 视图定义者_MySQL视图定义者权限和错误1356

bd96500e110b49cbb3cd949968f18be7.png

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?

解决方案

Instead of "create view..." try "create SQL SECURITY INVOKER view..."

I was having the same problem until I made this change.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值