2014年7月29日 星期二

MySQL 調教--Run OPTIMIZE TABLE to defragment tables

寫在前面:
--------------------------------------------------------------------------------------------------------
如果對於設定不熟的話,其實MySQL以經內建幾個文件可以使用,
路徑在/usr/share/mysql 下,  差異性在於機器的記憶體大小...

my-innodb-heavy-4G.cnf (4GB的記憶體)
my-huge.cnf (1~2GB的記憶體)
my-large.cnf (128~512MB的記憶體)
my-medium.cnf (64~128MB的記憶體)
my-small.cnf (小於64MB的記憶體)

--------------------------------------------------------------------------------------------------------
在執行MySQL的校正工具-mysqltuner.pl ,出現以下的報告

 Run OPTIMIZE TABLE to defragment tables for better performance
 Reduce your overall MySQL memory footprint for system stability
 Increase table_cache gradually to avoid file descriptor limits
 Read this before increasing table_cache over 64: http://bit.ly/1mi7c4C
 Optimize queries and/or use InnoDB to reduce lock wait...

處理方式:
執行以下命令 
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

(若出現以下錯誤:Error:  mysqlcheck doesn't support multiple contradicting commands.
可改用以下方式試試看:
mysqlcheck --auto-repair --optimize --all-databases -uroot -p
)


-------------------------------------------------------------------------------------------------

Add skip-innodb to MySQL configuration to disable InnoDB

處理方式:
編輯 /etc/my.cnf

在 [mysqld]下增加 skip-innodb 

記得重啟mysql

-------------------------------------------------------------------------------------------------
  Enable the slow query log to troubleshoot bad queries
處理方式:
系統建議可開啟slow query log 之功能來記錄執行特別久的 SQL,以供後續的分析,方法為增加兩行設定到 /etc/my.cnf
log_slow_queries= mysqld-slow.log
long_query_time= 10
設定後一樣需重新啟動 MySQL。

log_slow_queries 指定 slow query log 存放之檔名,預設存在 /var/lib/mysql/ 目錄下。
long_query_time 設定超過幾秒之 SQL Query 會被記錄在 log_slow_queries 之log 檔中,系統預設值為 10秒。


沒有留言:

張貼留言