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.