萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> MySQL服務器安裝完之後如何調節性能

MySQL服務器安裝完之後如何調節性能

   My favorite question during Interview for people to work as MySQL DBAs or be involved with MySQL Performance in some way is to ask them what should be tuned in MySQL Server straight after installation, assuming it was installed with default settings.

  在面試MySQL DBA或者那些打算做MySQL性能優化的人時,我最喜歡問題是:MySQL服務器按照默認設置安裝完之後,應該做哪些方面的調節呢?

  I’m surprised how many people fail to provide any reasonable answer to this question, and how many servers are where in wild which are running with default settings.

  令我很驚訝的是,有多少人對這個問題無法給出合理的答案,又有多少服務器都運行在默認的設置下。

  Even though you can tune quite a lot of variables in MySQL Servers only few of them are really important for most common workload. After you get these settings right other changes will most commonly offer only incremental performance improvements.

  盡管你可以調節很多MySQL服務器上的變量,但是在大多數通常的工作負載下,只有少數幾個才真正重要。如果你把這些變量設置正確了,那麼修改其他變量最多只能對系統性能改善有一定提升。

  key_buffer_size - Very important if you use MyISAM tables. Set up to 30-40% of available memory if you use MyISAM tables exclusively. Right size depends on amount of indexes, data size and workload - remember MyISAM uses OS cache to cache the data so you need to leave memory for it as well, and data can be much larger than indexes in many cases. Check however if all of key_buffer is used over time - it is not rare to see key_buffer being set to 4G while combined size of .MYI files is just 1GB. This would be just a waste. If you use few MyISAM tables you’ll want to keep it lower but still at least 16-32Mb so it is large enough to accommodate indexes for temporary tables which are created on disk.

  key_buffer_size - 這對MyISAM表來說非常重要。如果只是使用MyISAM表,可以把它設置為可用內存的 30-40%。合理的值取決於索引大小、數據量以及負載 -- 記住,MyISAM表會使用操作系統的緩存來緩存數據,因此需要留出部分內存給它們,很多情況下數據比索引大多了。盡管如此,需要總是檢查是否所有的 key_buffer 都被利用了 -- .MYI 文件只有 1GB,而 key_buffer 卻設置為 4GB 的情況是非常少的。這麼做太浪費了。如果你很少使用MyISAM表,那麼也保留低於 16-32MB 的 key_buffer_size 以適應給予磁盤的臨時表索引所需。

  innodb_buffer_pool_size This is very important variable to tune if you’re using Innodb tables. Innodb tables are much more sensitive to buffer size compared to MyISAM. MyISAM may work kind of OK with default key_buffer_size even with large data set but it will crawl with default innodb_buffer_pool_size. Also Innodb buffer pool caches both data and index pages so you do not need to leave space for OS cache so values up to 70-80% of memory often make sense for Innodb only installations. Same rules as for key_buffer apply - if you have small data set and it is not going to grow dramatically do not oversize innodb_buffer_pool_size you might find better use for memory available.

  innodb_buffer_pool_size - 這對Innodb表來說非常重要。Innodb相比MyISAM表對緩沖更為敏感。MyISAM可以在默認的 key_buffer_size 設置下運行的可以,然而Innodb在默認的 innodb_buffer_pool_size 設置下卻跟蝸牛似的。由於Innodb把數據和索引都緩存起來,無需留給操作系統太多的內存,因此如果只需要用Innodb的話則可以設置它高達 70-80% 的可用內存。一些應用於 key_buffer 的規則有 -- 如果你的數據量不大,並且不會暴增,那麼無需把 innodb_buffer_pool_size 設置的太大了。

  innodb_additional_pool_size This one does not really affect performance too much, at least on OS with decent memory allocators. Still you might want to have it 20MB (sometimes larger) so you can see how much memory Innodb allocates for misc needs.

  innodb_additional_pool_size - 這個選項對性能影響並不太多,至少在有差不多足夠內存可分配的操作系統上是這樣。不過如果你仍然想設置為 20MB(或者更大),因此就需要看一下Innodb其他需要分配的內存有多少。

  innodb_log_file_size Very important for write intensive workloads especially for large

        :更多精彩文章請關注三聯編程教程欄目。

copyright © 萬盛學電腦網 all rights reserved