檢視慢查詢中,表被update 或 select 次數

markzy5201190發表於2013-02-22
如下SQL語句,只適用於慢查詢資訊記錄,由原來的磁碟檔案存放,轉移到mysql.slow.log表中存放;

root@xx.xx.xx.xx:(none) 11:19:48>show variables like  '%output%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output    | TABLE  |
+---------------+-------+
1 row in set (0.00 sec);
達到目的;
SELECT replace(replace(SUBSTRING(sql_text,LOCATE('update',sql_text)+6,LOCATE('set',sql_text)-LOCATE('update',sql_text)-6),' ',''),char(10),''),count(0)
from mysql.slow_log 
WHERE start_time>='2013-02-21'#ADDDATE(NOW(),INTERVAL -60 MINUTE) 
AND (sql_text LIKE 'update%'
OR sql_text LIKE 'select%')
group by replace(SUBSTRING(sql_text,LOCATE('update',sql_text)+6,LOCATE('set',sql_text)-LOCATE('update',sql_text)-6),' ','')
ORDER BY 2 DESC,1;

已做備忘....

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26855487/viewspace-754562/,如需轉載,請註明出處,否則將追究法律責任。

相關文章