mysql+last_query_cost,MySQL 8 Select语句获取“ Last_query_cost”

本文介绍如何使用纯SELECT语句查询MySQL中的状态变量,如Last_query_cost。在MySQL 5.7及更早版本中,这些变量存储在INFORMATION_SCHEMA.GLOBAL_STATUS和INFORMATION_SCHEMA.SESSION_STATUS表中;而在MySQL 8.0中,则被移到了performance_schema中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There is a MySQL CLI command

SHOW STATUS LIKE 'Last_query_cost';

but how to get that info with plain SELECT Query?

Is there any kind of escaping/wrapping MySQL CLI command so it can be used in plain SELECT statement?

Perhaps there is a schema that I could query with SELECT in order to obtain the info provided by SHOW STATUS LIKE 'Last_query_cost'; command?

解决方案

In mysql v5.7 and earlier, all global and session variables are stored in the INFORMATION_SCHEMA GLOBAL_STATUS and SESSION_STATUS tables.

The GLOBAL_STATUS and SESSION_STATUS tables provide information about server status variables. Their contents correspond to the information produced by the SHOW GLOBAL STATUS and SHOW SESSION STATUS statements.

In mysql v8, these tables are moved to the performance schema, see mysql manual.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值