MySQL General log view MySQL run history

Source: Internet
Author: User

We sometimes need to look at the running history of MySQL, for example, when we do SQL optimizations, at least we need to know what SQL is running. The framework usually helps us to assemble SQL, so it's not always possible to print out SQL in the program, which requires MySQL's general
Log out.

View settings MySQL genneral log
‘%general_log%‘;setGLOBAL= off;// on-打开; off-关闭ONgeneral_log_file    /var/log/mysql/query.log
Using MySQL general log
Tail-f/path/to/log/query.log | grep yourtable13518 PrepareSELECT Count(*) as ' Count '  from ' Babysitter_tips ' WHERE(Tip_type =' 1 ') and(is_enable =1) and(Is_tip =2)13518QueryDESCRIBE ' Babysitter_tips '        13518 Closestmt13518 Prepare   SELECT ' Babysitter_tips '.* from ' Babysitter_tips ' WHERE(Tip_type =' 1 ') and(is_enable =1) and(Is_tip =2)ORDER  by ' Created_time ' descLIMIT5        13518Reset stmt13518 Closestmt13518 Prepare   SELECT Count(*) as ' Count '  from ' Babysitter_tips ' WHERE(Tip_type =' 1 ') and(is_enable =1) and(Is_tip =2) and(tip_id >15440)13518 Closestmt13518 Prepare   SELECT Count(*) as ' Count '  from ' Babysitter_tips ' WHERE(Tip_type =' 3 ') and(is_enable =1) and(Is_tip =2)13518QueryDESCRIBE ' Babysitter_tips '        13518 Closestmt13518 Prepare   SELECT ' Babysitter_tips '.* from ' Babysitter_tips ' WHERE(Tip_type =' 3 ') and(is_enable =1) and(Is_tip =2)ORDER  by ' Created_time ' descLIMIT5        13518Reset stmt13518 Closestmt13518 Prepare   SELECT Count(*) as ' Count '  from ' Babysitter_tips ' WHERE(Tip_type =' 3 ') and(is_enable =1) and(Is_tip =2) and(tip_id >"')13518 Closestmt13518 Prepare   SELECT Count(*) as ' Count '  from ' Babysitter_tips ' WHERE(Tip_type =' 2 ') and(is_enable =1) and(Is_tip =2)13518QueryDESCRIBE ' Babysitter_tips '        13518 Closestmt13518 Prepare   SELECT ' Babysitter_tips '.* from ' Babysitter_tips ' WHERE(Tip_type =' 2 ') and(is_enable =1) and(Is_tip =2)ORDER  by ' Created_time ' descLIMIT5        13518Reset stmt13518 Closestmt
Clean MySQL General log

The general log will be larger, so the default city is closed, so it's best to open it when needed and close it off. Suppose that Query.log is too large. can be deleted manually. In the case of general log open, the Query.log file is similar to the lock condition of the MySQL table and does not agree with the changes and deletions. Close the general log to be able to operate.

MySQL General log view MySQL run history

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.