我如何知道在我的数据库中触发了多少查询?

时间:2021-11-04 01:04:34

I have a employee management application . I am using mysql db.

我有一个员工管理应用程序。我正在使用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 insert query.

每当我运行任何功能时,都会在数据库中触发一个查询。就像添加员工一样,它会触发插入查询。

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.

我不想对我的java代码做任何更改。

Thanks.

5 个解决方案

#1


2  

You can use SHOW STATUS:

您可以使用SHOW STATUS:

SHOW GLOBAL STATUS LIKE 'Questions'

As documented under Server Status Variables:

如服务器状态变量中所述:

The status variables have the following meanings.

状态变量具有以下含义。

[ deletia ]

[deletia]

  • Questions

    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 COM_PING, COM_STATISTICS, COM_STMT_PREPARE, COM_STMT_CLOSE, or COM_STMT_RESET commands.

    服务器执行的语句数。这仅包括客户端发送到服务器的语句,而不包括存储程序中执行的语句,与Queries变量不同。此变量不计算COM_PING,COM_STATISTICS,COM_STMT_PREPARE,COM_STMT_CLOSE或COM_STMT_RESET命令。

Beware that:

  • the statistics are reset when FLUSH STATUS is issued.

    发出FLUSH STATUS时重置统计数据。

  • the SHOW STATUS command is itself a statement and will increment the Questions counter.

    SHOW STATUS命令本身就是一个语句,它将增加Questions计数器。

  • 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.

    这些统计信息是服务器范围的,因此将包括同一服务器上的其他数据库(如果存在) - 自2006年1月以来,每个数据库统计信息的功能请求已打开;在此期间,可以从google-mysql-tools / UserTableMonitoring获取每表统计信息。

#2


1  

You should execute queries as mentioned below:

您应该执行如下所述的查询:

  1. To get SELECT query count execute Show global status like 'com_select';

    要获取SELECT查询计数,请执行显示全局状态,如'com_select';

  2. To get UPDATE query count execute Show global status like 'com_update';

    要获得UPDATE查询计数,请执行显示全局状态,如'com_update';

  3. To get DELETE query count execute Show global status like 'com_delete';

    要获取DELETE查询计数,请执行显示全局状态,如'com_delete';

  4. To get INSERT query count execute Show global status like 'com_insert';

    要获取INSERT查询计数,请执行显示全局状态,如'com_insert';

You can also analyze General log or route your application via MySQL proxy to get all queries executed on a server.

您还可以分析常规日志或通过MySQL代理路由您的应用程序以获取在服务器上执行的所有查询。

#3


0  

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).

如果您不想修改代码,则可以使用触发器在数据库上跟踪此代码。限制是触发器只能在插入/更新/删除时触发,因此不能用于计数读取(选择)。

#4


0  

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.

当您使用munin(http://munin-monitoring.org/)(其他监视工具具有类似扩展)时,您可以使用mysql监视工具来显示有多少请求(在Insert / Update / Loaddata /中拆分)。你正在解雇。

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.

使用这些工具,您可以看到正在生成的使用情况和负载。特别是当数据发生变化时,可能会导致更多的访问/加载(缺少索引,因为大的m:n-tables,...更多的查询),您就会认出它。

It's extremely handy and you can do the check during your break. No typing, no thing, just check the graphs.

它非常方便,您可以在休息时进行检查。没有打字,没有东西,只需检查图表。

#5


0  

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.

这是一般查询日志手册页,可以帮助您入门。

#1


2  

You can use SHOW STATUS:

您可以使用SHOW STATUS:

SHOW GLOBAL STATUS LIKE 'Questions'

As documented under Server Status Variables:

如服务器状态变量中所述:

The status variables have the following meanings.

状态变量具有以下含义。

[ deletia ]

[deletia]

  • Questions

    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 COM_PING, COM_STATISTICS, COM_STMT_PREPARE, COM_STMT_CLOSE, or COM_STMT_RESET commands.

    服务器执行的语句数。这仅包括客户端发送到服务器的语句,而不包括存储程序中执行的语句,与Queries变量不同。此变量不计算COM_PING,COM_STATISTICS,COM_STMT_PREPARE,COM_STMT_CLOSE或COM_STMT_RESET命令。

Beware that:

  • the statistics are reset when FLUSH STATUS is issued.

    发出FLUSH STATUS时重置统计数据。

  • the SHOW STATUS command is itself a statement and will increment the Questions counter.

    SHOW STATUS命令本身就是一个语句,它将增加Questions计数器。

  • 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.

    这些统计信息是服务器范围的,因此将包括同一服务器上的其他数据库(如果存在) - 自2006年1月以来,每个数据库统计信息的功能请求已打开;在此期间,可以从google-mysql-tools / UserTableMonitoring获取每表统计信息。

#2


1  

You should execute queries as mentioned below:

您应该执行如下所述的查询:

  1. To get SELECT query count execute Show global status like 'com_select';

    要获取SELECT查询计数,请执行显示全局状态,如'com_select';

  2. To get UPDATE query count execute Show global status like 'com_update';

    要获得UPDATE查询计数,请执行显示全局状态,如'com_update';

  3. To get DELETE query count execute Show global status like 'com_delete';

    要获取DELETE查询计数,请执行显示全局状态,如'com_delete';

  4. To get INSERT query count execute Show global status like 'com_insert';

    要获取INSERT查询计数,请执行显示全局状态,如'com_insert';

You can also analyze General log or route your application via MySQL proxy to get all queries executed on a server.

您还可以分析常规日志或通过MySQL代理路由您的应用程序以获取在服务器上执行的所有查询。

#3


0  

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).

如果您不想修改代码,则可以使用触发器在数据库上跟踪此代码。限制是触发器只能在插入/更新/删除时触发,因此不能用于计数读取(选择)。

#4


0  

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.

当您使用munin(http://munin-monitoring.org/)(其他监视工具具有类似扩展)时,您可以使用mysql监视工具来显示有多少请求(在Insert / Update / Loaddata /中拆分)。你正在解雇。

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.

使用这些工具,您可以看到正在生成的使用情况和负载。特别是当数据发生变化时,可能会导致更多的访问/加载(缺少索引,因为大的m:n-tables,...更多的查询),您就会认出它。

It's extremely handy and you can do the check during your break. No typing, no thing, just check the graphs.

它非常方便,您可以在休息时进行检查。没有打字,没有东西,只需检查图表。

#5


0  

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.

这是一般查询日志手册页,可以帮助您入门。