MySQL query log

Source: Internet
Author: User

MySQL query log

Unlike Oracle, MySQL does not add a large number of debugging entries to the source code. Recently, it suddenly needs to debug the SQL Execution Process of MySQL. So I checked it and found that there is only one mechanism called query log. After the switch is turned on, all executed SQL statements will be recorded, which is very detailed and can basically achieve debugging. This is the official query log function description:

The general query log is a general record of what mysqld is doing. the server writes information to this log when clients connect or disconnect, And it logs each SQL statement received ed from clients. the general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

Mysqld writes statements to the query log in the order that it records es them, which might differ from the order in which they are executed. this logging order contrasts to the binary log, for which statements are written after they are executed but before any locks are released. (Also, the query log contains all statements, whereas the binary log does not contain statements that only select data .)

 

 

There are two ways to open the query log of MySQL:

1. Add the following startup parameters when starting MYSQL: "-- log [= file_name] Or-L [file_name] Option"

Before Version 5.1.6, the recorded query log can only be saved in one table in MySQL. After version 5.1.6, the query log can be saved in both table and file, in the database, a parameter named general_log has a value of 0 or 1, representing the start switch of query log, run "show variables like % log %" in MySQL to view all log-related parameters.

 

2. another way is to use the MySQL configuration file my. add a line "log = D:/temp_ SQL .log" to the end of INI. This method does not seem to be described in the official documentation, but is very practical.

 

In retrospect, Oracle was brave enough to leave the debug Code directly in the release, so as to maximize the guidance for error debugging and performance optimization during runtime. Now Oracle has acquired sun to own mysql. I don't know how this open-source free database will develop in the future.

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.