天天看点

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

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

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.