MySQL general log view MySQL execution history

Source: Internet
Author: User

We sometimes need to look at the execution history of MySQL, such as when we do SQL optimization, at least to know what SQL is executed, the framework will generally help us to assemble SQL, so in the program will not be able to print out SQL, this time need MySQL 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

General log will be larger, so the default city is closed, so it is best to open it when needed and close it. If you find Query.log is too large, you can delete it manually. In the case of general log open, the Query.log file resembles the lock condition of the MySQL table, does not allow the modification and deletion, and closes the general log to operate.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MySQL general log view MySQL execution 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.