Mysqlgenerallog view mysql execution history _ MySQL

Source: Internet
Author: User
We sometimes need to check the execution history of mysql. for example, when we perform SQL optimization, we should at least know what the executed SQL is. the framework will generally help us assemble the SQL, therefore, the SQL statement may not be printed in the program. mysql generallog is required at this time.

We sometimes need to check the execution history of mysql. for example, when we perform SQL optimization, we should at least know what the executed SQL is. the framework will generally help us assemble the SQL, therefore, the SQL statement may not be printed in the program. in this case, the general
Log.

View mysql genneral log settings
Show VARIABLES like '% general_log %'; set GLOBAL general_log = off; // on-open; off-disable general_log ONgeneral_log_file/var/log/mysql/query. log
Use mysql general log
tail -f /path/to/log/query.log | grep yourtable13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2)        13518 Query DESCRIBE `babysitter_tips`        13518 Close stmt        13518 Prepare   SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5        13518 Reset stmt        13518 Close stmt        13518 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 Close stmt        13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2)        13518 Query DESCRIBE `babysitter_tips`        13518 Close stmt        13518 Prepare   SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5        13518 Reset stmt        13518 Close stmt        13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2) AND (tip_id > '')        13518 Close stmt        13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '2') AND (is_enable = 1) AND (is_tip = 2)        13518 Query DESCRIBE `babysitter_tips`        13518 Close stmt        13518 Prepare   SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '2') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5        13518 Reset stmt        13518 Close stmt
Clear mysql general log

General log is relatively large, so it is disabled by default, so it is best to open it when needed and close it at will. If you find that query. log is too large, you can manually delete it. When the general log is opened, the query. log file is similar to the mysql table lock, and cannot be modified or deleted. you can simply close the general log.

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.