I have a
employee management application .
I am using mysql db.
In my application , i have functionality like
add /edit/delete /view .
Whenever i run any functionality , one
query is fired in database.
Like in add employee , it will fire
So i want to do something on my database, so that in see how many queries have been fired till date?
I dont want to do any changes on my java code.
You can use
SHOW GLOBAL STATUS LIKE 'Questions'
As documented under Server Status Variables:
The status variables have the following meanings.
[ deletia ]
The number of statements executed by the server. This includes only statements sent to the server by clients and not statements executed within stored programs, unlike the
Queries variable. This variable does not count
the statistics are reset when
FLUSH STATUS is issued.
SHOW STATUS command is itself a statement and will increment the
these statistics are server-wide and therefore will include other databases on the same server (if any exist)—a feature request for per-database statistics has been open since January 2006; in the meantime one can obtain per-table statistics from google-mysql-tools/UserTableMonitoring.</li> </ul>
You should execute queries as mentioned below:<ol> <li>
To get SELECT query count execute
Show global status like 'com_select';
To get UPDATE query count execute
Show global status like 'com_update';
To get DELETE query count execute
Show global status like 'com_delete';
To get INSERT query count execute
Show global status like 'com_insert';
You can also analyze General log or route your application via MySQL proxy to get all queries executed on a server.
If you don't want to modify your code then you can trace this on the database with triggers. The restriction is that triggers can only fire on insert/update/delete so can't be used to count reads (selects).
Maybe it's too "enterprise" and too "production" for your question.
When you use munin (http://munin-monitoring.org/) (other monitoring-tools have simular extenstions), you can use mysql-monitoring tools which show you how many requests (splitted in Insert/Update/Loaddata/...) you are firing.
With these tools, you see the usage and the load you are producing. Especially when data changes, and may cause more accesses/load (missing indices, more queries because of big m:n-tables, ...) you recognize it.
It's extremely handy and you can do the check during your break. No typing, no thing, just check the graphs.
I think that the most exact method, which needs no modifications to the database or application in order to operate, would be to configure your database management system to log all events.
You are left with a log file, which is a text file that can be analyzed on demand.
Here is the The General Query Log manual page that will get you started.