当我运行以下查询时,我得到一个错误:

SELECT
  `a`.`sl_id`                     AS `sl_id`,
  `a`.`quote_id`                  AS `quote_id`,
  `a`.`sl_date`                   AS `sl_date`,
  `a`.`sl_type`                   AS `sl_type`,
  `a`.`sl_status`                 AS `sl_status`,
  `b`.`client_id`                 AS `client_id`,
  `b`.`business`                  AS `business`,
  `b`.`affaire_type`              AS `affaire_type`,
  `b`.`quotation_date`            AS `quotation_date`,
  `b`.`total_sale_price_with_tax` AS `total_sale_price_with_tax`,
  `b`.`STATUS`                    AS `status`,
  `b`.`customer_name`             AS `customer_name`
FROM `tbl_supplier_list` `a`
  LEFT JOIN `view_quotes` `b`
    ON (`b`.`quote_id` = `a`.`quote_id`)
LIMIT 0, 30

错误信息是:

#1449 - The user specified as a definer ('web2vi'@'%') does not exist

为什么会出现这个错误?我该怎么解决呢?


当前回答

我的5美分。

当我试图从视图中选择时,我也犯了同样的错误。

然而,问题似乎是这个视图,选择从另一个视图,从备份从不同的服务器恢复。

事实上,是的,用户是无效的,但从第一眼看不清楚在哪里。

其他回答

grant all on *.* to 'username'@'%' identified by 'password' with grant option;

例子:

grant all on *.* to 'web2vi'@'%' identified by 'password' with grant option;

遵循以下步骤:

进入PHPMyAdmin 选择数据库 选择您的表格 在顶部菜单中点击“触发器” 点击“编辑”编辑触发器 将定义器从[user@localhost]更改为root@localhost

希望能有所帮助

最初创建SQL视图或过程的用户已被删除。如果您重新创建该用户,它应该可以解决您的错误。

为什么会出现这个错误?我该怎么解决呢?

我花了一个小时才对这样的问题做出决定。但是,在我的例子中,我运行了这个:

mysql> UPDATE `users` SET `somefield` = 1 WHERE `user_id` = 2;
ERROR 1449 (HY000): The user specified as a definer ('root'@'%') does not exist

如果你真的想找到问题,只需要逐个运行这些命令:

SHOW PROCEDURE STATUS;
SHOW FUNCTION STATUS;
SHOW TRIGGERS;
SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';

...然后,在每个字段之后,查找字段'definer'。

在我的例子中,它是一个老旧的触发器,某个开发人员忘记删除了。

通过运行以下注释修复。

grant all on *.* to 'web2vi'@'%' identified by 'root' with grant option;
FLUSH PRIVILEGES;

如果你得到的是some_other而不是web2vi,那么你必须相应地改变名称。