问题
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