Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MySQL status in a query

Tags:

database

mysql

Is it possible to use the server status variables in a MySQL query?

I can see various metrics from 'show status' but how do I calculate derived values (e.g. the query cache hit ratio)

show global status like 'Qcache_inserts';
show global status like 'Qcache_not_cached';
show global status like 'Qcache_hits';

Ho do I get Qcache_hits/(Qcache_hits+Qcache_inserts+Qcache_not_cached)?

like image 530
symcbean Avatar asked May 10 '12 09:05

symcbean


People also ask

Is status a keyword in MySQL?

You're correct that STATUS is a keyword, likely owing to SHOW STATUS . If renaming the column isn't much of a chore for you, changing the name is the best choice.

Is active in MySQL?

The active or total connection can be known with the help of threads_connected variable. The variable tells about the number of currently open connections. mysql> show status where `variable_name` = 'Threads_connected'; Here is the output.

What is DESC command in MySQL?

The DESC is the short form of DESCRIBE command and used to dipslay the information about a table like column names and constraints on column name. The DESCRIBE command is equivalent to the following command − SHOW columns from yourTableName command.


1 Answers

generally you can access that info due this select:

SELECT
   VARIABLE_NAME,
   VARIABLE_VALUE
 FROM
   INFORMATION_SCHEMA.GLOBAL_STATUS

You could make the calculation you want like this:

select (g1.VARIABLE_VALUE / (g1.VARIABLE_VALUE + g2.VARIABLE_VALUE + g3.VARIABLE_VALUE)) as result
FROM INFORMATION_SCHEMA.GLOBAL_STATUS g1
inner join INFORMATION_SCHEMA.GLOBAL_STATUS g2
inner join INFORMATION_SCHEMA.GLOBAL_STATUS g3
where g1.VARIABLE_NAME = 'Qcache_hits'
and g2.VARIABLE_NAME = 'Qcache_inserts'
and g3.VARIABLE_NAME = 'Qcache_not_cached'
like image 85
juergen d Avatar answered Sep 28 '22 08:09

juergen d