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