關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • MySQL 微調技巧

    Posted on November 6th, 2009 Sam Tang No comments

    以下會介紹一些簡易的 MySQL 效能微調技巧,這些方法都是透過 my.cnf 的參數完成,而不需要重新編譯 MySQL。

    Key Buffer
    key buffer 是系統索引可用的緩存空間大小,對處理索引有很大的影響。設定 key buffer 的大小要根據自己的需要而定,而一個較簡單的方法是使用 25% 的記憶體空間作為 key buffer 使用。如果是獨立的資料庫伺服器可考慮使用更大的空間,例如 50%。
    通這設定 key buffer 的大小,可以減少硬碟 I/O 操作對 MySQL 的影響。

    以下是 key buffer 在 my.cnf 的設定方法:

    key_buffer = 512M

    Query Cache
    這是 SQL Query 的緩存,將 query 的查詢結果暫存在記憶體裡面,直至資料被更新為止。

    query_cache_size = 128MB
    query_cache_limit = 4MB

    Table Cache
    對於同時要存取多個資料表十分重要,這是設定同時可開啟資料表的數目。

    table_cache = 512

    Sort Buffers
    sort_buffer_size (在舊版本是 sort_buffer) 是設定 grouping 及 sorting 的緩存。

    sort_buffer_size = 32M
    myisam_sort_buffer_size = 32M


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word