Detailed explanation of how to monitor MySQL statements

Detailed explanation of how to monitor MySQL statements

Quick Reading

Why do we need to monitor SQL statements, how to monitor them, and what are the ways to monitor them.

We know that there is a tool called SQL Profile in SQL Server, which can monitor the SQL statements executed in SQL Server in real time to facilitate debugging bugs or confirm the final generated SQL statements.

Why monitor SQL statements?

  1. As the program grows, SQL statements may be called from multiple places. You cannot confirm whether only the statement you need is executed at the current time.
  2. Some persistence layer frameworks use LINQ syntax to write SQL, which is not convenient for outputting SQL statements in the program.
  3. There is no way to change the program that is running online. But need to confirm where the problem is? Which SQL statements were executed. You can determine where the error occurred based on the sql statement.

How to monitor sql statements in mysql?

By default, MySQL does not enable SQL statement monitoring. When it needs to be enabled, execute the following command.

SHOW VARIABLES LIKE "general_log%"; -- off means off, if it is on, it has been turned on SET GLOBAL general_log = 'ON'; --Turn on log monitoring.

I have it turned on. If it is not turned on, general_log will show off.

As shown in the figure below, you can see the default path where the log is saved.

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

Next we execute a few sql statements to check

Execute SQL

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

Next, let’s look at the log.

You can see that the log contains

Time Id Command Argument

Corresponding to time, id, command, and parameter respectively

Parameters refer to the SQL statements that are executed.

How to display the SQL statement in MySQL in the table

It is inconvenient 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 method can be displayed in real time, but I don’t know why the new SQL cannot be displayed in real time. I will record it first.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of MySQL monitoring tool mysql-monitor
  • Detailed explanation of non-primary key column overflow monitoring in MySQL tables
  • Use Grafana+Prometheus to monitor MySQL service performance
  • Detailed tutorial on how to monitor Nginx/Tomcat/MySQL using Zabbix
  • MySQL index usage monitoring skills (worth collecting!)
  • Detailed explanation of how Zabbix monitors the master-slave status of MySQL
  • MySQL database monitoring software lepus usage problems and solutions
  • Detailed explanation of performance monitoring of MySQL server using Prometheus and Grafana
  • Introduction to the use of MySQL real-time monitoring tool orztop
  • Summary of the actual simulation monitoring MySQL service shell script
  • Basic tutorial on installing and configuring Zabbix to monitor MySQL
  • Briefly describe mysql monitoring group replication

<<:  Detailed explanation of native Javascript inheritance methods and their advantages and disadvantages

>>:  Detailed explanation of the complete usage example of developing hyperf under Docker

Recommend

html option disable select select disable option example

Copy code The code is as follows: <select> ...

MySQL statement summary

Table of contents 1. Select database USE 2. Displ...

Record the process of connecting to the local Linux virtual machine via SSH

Experimental environment: Physical machine Window...

Samba server configuration under Centos7 (actual combat)

Samba Overview Samba is a free software that impl...

Detailed explanation of tinyMCE usage and experience

Detailed explanation of tinyMCE usage initializat...

The DOCTYPE mode selection mechanism of well-known browsers

Document Scope This article covers mode switching...

Implementation of CSS scroll bar style settings

webkit scrollbar style reset 1. The scrollbar con...

How to use Node.js to determine whether a png image has transparent pixels

background PNG images take up more storage space ...

Use viewport in meta tag to define screen css

<meta name="viewport" content="w...

How to use worker_threads to create new threads in nodejs

Introduction As mentioned in the previous article...

Installation tutorial of mysql8.0rpm on centos7

First, download the diagram 1. First uninstall th...

How to implement function currying and decurrying in Javascript

Function currying (black question mark face)? ? ?...

Zen HTML Elements Friends who use zen coding can collect it

html ¶ <html></html> html:xml ¶ <h...

How to Install Oracle Java 14 on Ubuntu Linux

Recently, Oracle announced the public availabilit...