How to record SQL Execution statements in a MySQL database

Source: Internet
Author: User
Today, a colleague asked me to help me read a report. This report was generated by an open-source system and the background database uses MySQL. the problem is that the data in one report is incorrect. At that time, the other report was correct. Therefore, we hope to find the background logic and modify the report. This is my first contact with MySQL, so it takes time to study

Today, a colleague asked me to help me read a report. This report was generated by an open-source system and the background database uses MySQL. the problem is that the data in one report is incorrect. At that time, the other report was correct. Therefore, we hope to find the background logic and modify the report. This is my first contact with MySQL, so it takes time to study

Today, a colleague asked me to help me read a report. This report was generated by an open-source system and the background database uses MySQL. the problem is that the data in one report is incorrect. At that time, the other report was correct. Therefore, we hope to find the background logic and modify the report.

This is my first time in contact with MySQL, so it takes time to study it. At that time, the idea was to view the running SQL statements like SQL Server or Oracle Trace.

Start to connect to MySQL. Check Help and log on with the Root Super User. The system keeps prompting that the error cannot be connected to Localhost. Then we can see that the parameter is the port specified by P, add the port to connect to the instance.

After logon, run show processlist, but only some spids are displayed, without detailed SQL statements.

Then I thought about finding a GUI tool to capture the Trace. I saw that MySQL provided some logs that could be used to record the executed SQL and allowed slow SQL. The command is as follows:

-- Enable the SQL Execution record Function
Set global log_output = 'table'; -- output to TABLE
Set global log = ON; -- enable the general_log function for all command execution records. All statements: successful and unsuccessful.
Set global log_slow_queries = ON; -- open the slow query SQL record slow_log and run the slow query statement and the statement without using the index successfully.
Set global long_query_time = 0.1; -- slow query time limit (seconds)
Set global log_queries_not_using_indexes = ON; -- Records SQL statements that do not use indexes.

-- Query SQL Execution records
Select * from mysql. slow_log order by 1; -- executed successfully: Slow query statement, and statement without using Index
Select * from mysql. general_log order by 1; -- all statements: successful and unsuccessful.

-- Disable SQL Execution records
Set global log = OFF;
Set global log_slow_queries = OFF;

But I directly reported an error when running, saying "unknown system variable logoutput ".

Use show variables to view the current configurable options. The configuration items corresponding to global log_output are not displayed. MYSQL configuration documents cannot be found at night on the server.

Let's look at the Help documentation for version 5.1. Is it because of version issues? With this question, I checked @ Version. Our Version is 4.1. Then I checked the Help File of 4.1, so there would be no configuration items above.

Although the Trace is not caught, the corresponding information is found because the column to be queried is known, and the Report is correct after the error data is changed. It seems that you have to take a moment to know about MYSQL. After all, many open-source software uses this database as the background.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.