-
Notifications
You must be signed in to change notification settings - Fork 111
ps_is_account_enabled()
xiaoboluo768 edited this page Jun 9, 2020
·
2 revisions
-
检查在setup_actors表中是否启用了对应account的监控功能,返回YES或者NO
-
参数:
- in_host VARCHAR(60):要检查的帐户的主机名
- in_user VARCHAR(32):要检查的帐户的用户名
-
返回值:一个枚举类型值,ENUM('YES','NO'),注意:返回值仅仅是依赖于在setup_actors表中找匹配记录而不管该帐号是否在mysql.user表中存在,如果在setup_actors表中开启了任意帐号的监控,那么就算在mysql.user中不存在的用户,也会返回YES
-
定义语句
DROP FUNCTION IF EXISTS ps_is_account_enabled;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_account_enabled (
in_host VARCHAR(60),
in_user VARCHAR(32)
)
RETURNS ENUM('YES', 'NO')
COMMENT '
Description
-----------
Determines whether instrumentation of an account is enabled
within Performance Schema.
Parameters
-----------
in_host VARCHAR(60):
The hostname of the account to check.
in_user VARCHAR(32):
The username of the account to check.
Returns
-----------
ENUM(\'YES\', \'NO\', \'PARTIAL\')
Example
-----------
mysql> SELECT sys.ps_is_account_enabled(\'localhost\', \'root\');
+------------------------------------------------+
| sys.ps_is_account_enabled(\'localhost\', \'root\') |
+------------------------------------------------+
| YES |
+------------------------------------------------+
1 row in set (0.01 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
RETURN IF(EXISTS(SELECT 1
FROM performance_schema.setup_actors
WHERE (`HOST` = '%' OR in_host LIKE `HOST`)
AND (`USER` = '%' OR `USER` = in_user)
AND (`ENABLED` = 'YES')
),
'YES', 'NO'
);
END$$
DELIMITER ;
上一篇: list_drop()函数 | 下一篇: ps_is_consumer_enabled()函数
- 验证、测试、整理:罗小波
- QQ:309969177
- 提示:本系列文章的主体结构遵循Oracle MySQL 官方 5.7 手册中,关于information_schema、mysql schema、performance_schema、sys schema的章节结构体系,并额外添加了一些验证、测试数据。鉴于本人精力和能力有限,难免出现一些纰漏,欢迎大家踊跃指正!