show status 查看當前鏈接的服務器狀態mysql
show global status 查看mysql服務器啓動以來的狀態
show global variables 查看mysql服務器配置的變量sql
增刪改的統計vim
查看 insert delete update select查詢總數
show global status like "com_insert%"
segmentfault
show global status like "com_delete%"
服務器
show global status like "com_update%"
spa
show global status like "com_select%"
日誌
Innodb影響行數code
show global status like "innodb_rows%";
索引
mysql鏈接總次數ip
show global status like "connection%";
包括成功和不成功的鏈接
mysql已經工做的秒數
show global status like "uptime%";
查看mysql慢查詢次數
show global status like "%slow%";
查看慢查詢日誌相關設置
show global variables like "%slow%";
log_slow_queries = on slow_query_log = on 代表慢查詢日誌已經開啓
slow_query_log_file 慢查詢日誌文件的路徑
show global variables like "%long_query%";
查看慢查詢執行時間粒度
配置my.conf
general_log = on general_log_file = /home/mysql-run/mysql.log
代表日誌已經開啓
配置my.conf
vim /etc/my.cnf
slow-query-log = on slow_query_log_file = /home/mysql-run/mysql_slow.log long_query_time = 10 #慢查詢執行時間記錄粒度 默認是10秒 log_queries_not_using_indexes = off #記錄沒有使用索引的查詢 不論執行有多塊
查看慢查詢日誌
cat mysql_slow.log
exiplain sql
或者使用desc sql
select_type : 單表查詢
rows: 查詢掃描的行數
key:用到的索引
key_length:用到的索引的長度
extra: using index 表示使用索引過濾掉不須要的行
myisam 索引存放於 .MYI文件中 與數據文件.MYD 分開 myisam索引能夠壓縮
Innodb表中索引和數據存放同一個文件中共享表空間
更多索引相關知識請點擊:http://www.javashuo.com/article/p-xobdpkqp-cx.html