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