標籤:
一、關於慢查詢設定和分析
尋找慢查詢參數
mysql> show variables like ‘long%‘;+-----------------+----------+| Variable_name | Value |+-----------------+----------+| long_query_time | 10.000000 |+-----------------+----------+
mysql> show variables like ‘slow%‘;+---------------------+--------------------------------+| Variable_name | Value |+---------------------+--------------------------------+| slow_launch_time | 2 || slow_query_log | OFF || slow_query_log_file | /var/lib/mysql/ubuntu-slow.log |+---------------------+--------------------------------+
mysql> show variables like ‘%queries%‘;+-------------------------------+-------+| Variable_name | Value |+-------------------------------+-------+| log_queries_not_using_indexes | OFF || log_slow_queries | ON |+-------------------------------+-------+
設定慢查詢參數(作者建議設定為1s)
mysql> set global long_query_time=1;
mysql> set global slow_query_log=‘ON‘;
有些朋友除了設定以上的還會將查詢中未帶索引的語句也設定為on(即log_queries_not_using_indexes),大家可以根據當前的需求來確定是否需要增加。
這樣大家就可以根據相應的日誌去進行最佳化了,當然以上這塊還是主要針對mysql語句進行最佳化
二、show processlist、show full processlist查看和分析
show processlist:主要有以下幾列
+----------+------+-----------+------+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----------+------+-----------+------+---------+------+-------+------------------+
除了一中進行一個日誌的最佳化外,當然show processlist也是一個方式,如果mysql進程一直處於一個較高的負載的時候,show processlist也是一個不錯的選擇,詳細的參數簡介我就不介紹了,相信網上還是有很多的資料的
網站瓶頸分析—MYSQL效能分析