Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation on the method of monitoring mysql statement

2025-05-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Fast reading

Why to monitor sql statements, and how to monitor, there are several ways to monitor.

We know that there is a tool in sql server called sql profile, which can monitor the sql statements executed in sql server in real time to facilitate debugging bug or confirming the resulting sql statements.

Why monitor sql statements?

Because when the program is big, the sql statement may be called in multiple places. You cannot confirm that only the statement you need has been executed at the current time. Some persistence layer frameworks use the syntax of linq to write sql, so it is not convenient to output the program running on the line of sq statements, and there is no way to change the program. But you need to confirm what went wrong? Which sql statements were executed. You can tell what went wrong based on the sql statement.

How do I monitor sql statements in mysql?

The default mysql is monitored by sql statements that are not enabled. Execute the following command when you need to open it.

SHOW VARIABLES LIKE "general_log%";-- off is disabled. If on means SET GLOBAL general_log is enabled, log monitoring is enabled.

I am already open state, if not open, general_log is the display of off.

As shown in the following figure, you will see the path location where the log is saved by default

C:\ ProgramData\ MySQL\ MySQL Server 5.5\ Data\ hcb-PC.log

Next let's execute a few sql statements to see

Execute sql

SELECT * FROM `platform`update `platform`SET platform_type=2 WHERE id=1

Next, let's take a look at the log.

You can see that the log contains

Time Id Command Argument

Corresponding time, id, command, parameter, respectively

Parameter refers to the sql statement that is executed.

How to make sql statements in mysql appear in a table

It is not convenient to view in the log, what if the sql statement is displayed in a table in the database?

Execute the following sql

SET GLOBAL log_output = 'TABLE'; SELECT * FROM mysql.general_log ORDER BY event_time DESC

Display with processlist

USE `information_ schema`; SELECT * FROM PROCESSLIST WHERE info IS NOT NULL

It is said that this way can be displayed in real time, but I don't know why I can't display the new sql in real time.

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report