MySQL 8 Select Statement to get 'Last_query_cost'

夙愿已清 提交于 2020-01-25 04:04:04

问题


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?


回答1:


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

As mysql manual says:

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.




回答2:


Using the information provided in the accepted answer, SELECT query to get the Last_query_cost (MySQL8):

SELECT `variable_value` 
FROM `performance_schema`.`session_status` 
WHERE `variable_name` = 'Last_query_cost';


来源:https://stackoverflow.com/questions/58581461/mysql-8-select-statement-to-get-last-query-cost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!