当我尝试创建一些但是当我调用它时出现错误1356:
创建视图
CREATE VIEW monitoring_consult AS (
SELECT
m.id,
account.valor AS 'phone_number',
IF((c.valor REGEXP '^[0-9]+$' OR c.valor IS NULL) AND cn.short_name IS NOT NULL, cn.short_name, c.valor) AS 'category',
IF(pn.id IS NOT NULL, pn.id, p.valor) AS 'provider',
n.valor AS 'nominal',
m.last_page,
pn.name AS 'provider_name',
IF(pay.valor is null, 'Uncompleted', pay.valor) AS 'payment',
timeEnd,
DATE_FORMAT(m.timeEnd, '%d/%m/%Y') as 'date'
FROM
monitoring AS m
LEFT JOIN feature AS account ON m.id = account.id AND account.valor IS NOT NULL AND (account.page = 'PV') AND account.type = 'send'
LEFT JOIN feature AS c ON m.id = c.id_monitoring AND c.valor IS NOT NULL AND (c.page = 'MA' OR c.page = 'IN') AND c.type = 'select'
LEFT JOIN feature AS p ON m.id = p.id_monitoring AND p.page = 'PO' AND p.valor IS NOT NULL AND p.type = 'select'
LEFT JOIN feature AS n ON m.id = n.id_monitoring AND n.valor IS NOT NULL AND n.page = 'OAP' AND n.type = 'select'
LEFT JOIN feature AS pay ON m.id = pay.id_monitoring AND m.last_page = 'OK' AND pay.type = 'userAction' AND pay.name = 'paymentStatus' AND pay.valor = 'Completed'
LEFT JOIN terminais AS term ON m.id_terminal = term.id
LEFT JOIN provider AS pn ON (p.valor = pn.id) OR (c.valor REGEXP '^[0-9]+$' AND c.valor = pn.id)
LEFT JOIN category AS cn ON pn.id_category = cn.id
group by m.id
having category is not null
)
调用视图:
select * from monitoring_consult
返回:
Error Code: 1356. View 'qiwi.monitoring_consult' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
Mysql版本 - 5.5.32-log
有人知道为什么会这样吗?
答案 0 :(得分:4)
首先抱歉我的英语, 每次我导入mysqldump导出时都会发生这个特殊问题,并在其中创建自动视图, 出现这样的问题是因为在mysqldump中创建了视图(再次重新导入时),使用" SQL SECURITY DEFINER", 我不知道它是否是一个mysql错误,但对我来说删除并应用视图的新权限,并没有解决问题,重新创建没有" SQL安全定义器的视图",解决我的问题问题,我希望这是你的情况。
Ciao Massimiliano。
答案 1 :(得分:1)
我得到了相同的错误代码,并且能够将其固定下来。当两个(或更多?)级别的对象不再可用时,似乎会出现这种情况。这是一些重新创建问题的代码。
create table `table1` (`id` int(11), `col1` varchar(16);
insert into `table1` (`id`, `col1`) values (1, 'Foo'), (2, 'Bar');
create view `view_sub` as SELECT `id`, `col1` from `table1`;
# if you drop here you'll get error code 1146: table1 doesn't exist
create view `view_err` as SELECT `id`, `col1` from `view_sub`;
drop table `table1`;
select * from `view_err`
# should get you error code 1356: references invalid table(s), etc
我不知道你的from子句中的任何内容是否是一个视图,但terminais
的(似乎是)错字可能会导致它。
答案 2 :(得分:0)
这些是案例
答案 3 :(得分:0)
创建视图时,请尝试指定这样的定义器:
CREATE
ALGORITHM = UNDEFINED
DEFINER = `user`@`%`
SQL SECURITY DEFINER
VIEW `monitoring_consult` AS ...
其中DEFINER user
必须对链接到视图的任何表具有适当的权限
答案 4 :(得分:0)
嗨,我在更改数据库模型后收到此错误。可能是现有视图引用了不存在的字段。
因此解决方案是删除当前视图并创建一个新视图,并考虑新模型而不是关注用户权限。
希望对某人有帮助:)
答案 5 :(得分:0)
我有同样的问题。虽然我仍然不知道是什么引起了问题,但是由于视图使用的所有表都没有更改。
我的解决方案是删除旧视图,并在以下视图的顶部指定一次,以创建一个新视图。
use databasename;