惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
I
InfoQ
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
The Cloudflare Blog
罗磊的独立博客

祈雨的笔记

安全多方计算MPC spark原理解析 kueue执行源码分析 spark on k8s执行源码分析 spark-operator源码解析 系统压测遇到的缓存击穿问题 我的世界PC与安卓联机 蚂蚁金服流量投放平台的AIG改造 G1大对象致Old区占用率高 日志打印导致接口响应率下跌分析 Groovy加载类导致OOM分析 ERROR日志打印导致CPU满载 记OceanBase死锁超时 应用发版期间服务响应超时 Ark Serverless初探 系统优化复盘一二三 Kong网关初探 API网关选型调研 CPU火焰图常用工具 配置中心选型调研 root操作Nginx导致用户组错误 基于Proxifier使用代理 FastJSON字段智能匹配踩坑 Nacos初探 记一次Nginx服务器CPU满荷载故障 基于券系统分库分表的思考 limit不参与SQL成本计算致索引失效 Linux常用性能监控命令 golang低版本http2偶现400 hostname in certificate didn't match
The user specified as a definer does not exist
祈雨的笔记 · 2021-03-20 · via 祈雨的笔记

描述

mysql管理员给调用方创建了一个名为test的用户,并授权了指定host,效果如下:

1
2
3
4
5
6
7
8
mysql> select user,host from mysql.user where user = 'test';
+------+------------+
| user | host |
+------+------------+
| test | 172.17.0.2 |
| test | 172.17.0.3 |
+------+------------+
2 rows in set (0.01 sec)

随后管理员创建了名为test_proc的存储过程,但调用方使用test用户调用存储过程时报如下错误:

1
2
mysql> call test_proc;
ERROR 1449 (HY000): The user specified as a definer ('test'@'%') does not exist

复现

先创建名为test的用户,并授权指定host(不要授权%的host权限),再给予限定的SQL执行权限。

1
2
3
4
5
-- drop user test@'%';
CREATE USER 'test'@'172.17.0.2' IDENTIFIED BY '123456';
CREATE USER 'test'@'172.17.0.3' IDENTIFIED BY '123456';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, EXECUTE ON *.* TO 'test'@'172.17.0.2';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, EXECUTE ON *.* TO 'test'@'172.17.0.3';

创建名为test_proc的存储过程,并通过definer指明该存储过程的调用者权限为test用户。

1
2
3
4
5
6
delimiter ;;
CREATE definer='test' PROCEDURE test_proc()
BEGIN
select 1;
END ;;
delimiter ;

查看名为test_proc的存储过程,发现当definerhost值缺省时默认使用的%host值。

1
2
3
4
5
6
7
mysql> select routine_name,definer from information_schema.routines where routine_name='test_proc';
+--------------+---------+
| ROUTINE_NAME | DEFINER |
+--------------+---------+
| test_proc | test@% |
+--------------+---------+
1 row in set (0.00 sec)

definer='test'等效于'test'@'%'

1
2
3
4
5
6
delimiter ;;
CREATE definer='test'@'%' PROCEDURE test_proc()
BEGIN
select 1;
END ;;
delimiter ;
1
2
3
4
5
6
7
mysql> select routine_name,definer from information_schema.routines where routine_name='test_proc';
+--------------+---------+
| ROUTINE_NAME | DEFINER |
+--------------+---------+
| test_proc | test@% |
+--------------+---------+
1 row in set (0.00 sec)

最后调用名为test_proc的存储过程,mysql返回异常The user specified as a definer ('test'@'%') does not exist

1
2
mysql> call test_proc;
ERROR 1449 (HY000): The user specified as a definer ('test'@'%') does not exist

解决

create-procedure.html

1
2
3
4
5
> CREATE DEFINER = 'admin'@'localhost' PROCEDURE account_count()
> BEGIN
> SELECT 'Number of accounts:', COUNT(*) FROM mysql.user;
> END;
>

The procedure is assigned a DEFINER account of ‘admin’@’localhost’ no matter which user defines it. It executes with the privileges of that account no matter which user invokes it (because the default security characteristic is DEFINER). The procedure succeeds or fails depending on whether invoker has the EXECUTE privilege for it and ‘admin’@’localhost’ has the SELECT privilege for the mysql.user table.

无论哪个用户执行存储过程,都将以该存储过程的definer定义的用户来执行。由于存储过程创建时definer错误,导致该存储过程指定了一个不存在的用户,因此只需要将该不存在的用户创建出来或者修改存储过程,使其重新指定到一个已存在且有权限的用户即可。

创建缺失用户

1
2
3
4
5
6
7
mysql> select routine_name,definer from information_schema.routines where routine_name='test_proc';
+--------------+---------+
| ROUTINE_NAME | DEFINER |
+--------------+---------+
| test_proc | test@% |
+--------------+---------+
1 row in set (0.00 sec)
1
2
CREATE USER 'test'@'%' IDENTIFIED BY '123456';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, EXECUTE ON *.* TO 'test'@'%';
1
2
3
4
5
6
7
mysql> call test_proc;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

修改DEFINER

为了修改definer,删除原先错误的存储过程,重新创建,并指定definer为当前用户。

1
2
3
4
5
6
7
mysql> select current_user();
+-----------------+
| current_user() |
+-----------------+
| test@172.17.0.2 |
+-----------------+
1 row in set (0.00 sec)
1
drop procedure test_proc;
1
2
3
4
5
6
delimiter ;;
CREATE definer='test'@'172.17.0.2' PROCEDURE test_proc()
BEGIN
select 1;
END ;;
delimiter ;
1
2
3
4
5
6
7
mysql> select routine_name,definer from information_schema.routines where routine_name='test_proc';
+--------------+-----------------+
| ROUTINE_NAME | DEFINER |
+--------------+-----------------+
| test_proc | test@172.17.0.2 |
+--------------+-----------------+
1 row in set (0.01 sec)
1
2
3
4
5
6
7
mysql> call test_proc;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)