淺析Mysql的my.ini檔案

南蠻蟲發表於2012-08-22
轉載:http://hunanpengdake.iteye.com/admin/blogs/1647725 

今天閒的蛋疼,沒事想了解mysql,大家都知道在配置Mysql的過程中,my.ini非常重要,一直對其深感迷惑,那麼鼓起勇氣,看看mysql的 my.ini的真實面目(小弟E文一直很差,有錯誤的地方請各位指出): 

第一步,我們找到mysql安裝檔案下面的my.ini檔案,開啟可以看到第一句: 
# MySQL Server Instance Configuration File 
Mysql服務例項配置檔案 

好,我們們撇開那些不是那麼重要的字幕,直接進入重點,看看它可以配置些什麼,和到底配置了些什麼,那麼帶著這樣的心態,我們往下看。
 

CLIENT SECTION 
客戶端章節:
 
[client] 
port=3306            埠號=3306 

[mysql] 
default-character-set=latin1    預設字元編碼=latin1 

SERVER SECTION 
服務端章節
 
[mysqld] 

# The TCP/IP Port the MySQL Server will listen on 
TCP/IP Port 監聽mysql的埠號    
port=3306 


#Path to installation directory. All paths are usually resolved relative to this.  
安裝目錄路徑 。所有的路徑都是作為這個路徑的相對路徑。 
basedir="E:/programfile/MySql5.1/" 

#Path to the database root 
資料庫資料的根路徑 
datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/" 

# The default character set that will be used when a new schema or table is 
# created and no character set is defined 
預設的字符集編碼作用於當一個新的schema 或者表被建立的時候沒有指定字符集。 
default-character-set=latin1 

# The default storage engine that will be used when create new tables when 
預設的儲存引擎作用於當建立新表的時候 
default-storage-engine=INNODB 

# Set the SQL mode to strict 
設定嚴格的SQL模型 

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 


# The maximum amount of concurrent sessions the MySQL server will 
# allow. One of these connections will be reserved for a user with 
# SUPER privileges to allow the administrator to login even if the 
# connection limit has been reached. 
Mysql 服務端允許最大的併發數,其中一個連線將留給使用者使用超級許可權連線資料庫,即使連線數已經達到最高限額 
max_connections=100 

# Query cache is used to cache SELECT results and later return them 
# without actual executing the same query once again. Having the query 
# cache enabled may result in significant speed improvements, if your 
# have a lot of identical queries and rarely changing tables. See the 
# "Qcache_lowmem_prunes" status variable to check if the current value 
# is high enough for your load. 
# Note: In case your tables change very often or if your queries are 
# textually different every time, the query cache may result in a 
# slowdown instead of a performance improvement. 
查詢快取用於在快取中SELECT結果,返回不是實際查詢資料庫的結果。 
從快取中查詢的結果會顯著的提升查詢速度,如果你有很多相同的查詢和很少改變表結構。 
檢視“Qcache_lowmem_prunes”狀態變數來檢查當前值對於你的負載是否足夠高。 
NOTE:如果你的表結構經常改變或者,你每次查詢都不相同,那麼使用查詢快取結果可能不是一個效能改進。
 
query_cache_size=15M 

# The number of open tables for all threads. Increasing this value 
# increases the number of file descriptors that mysqld requires. 
# Therefore you have to make sure to set the amount of open files 
# allowed to at least 4096 in the variable "open-files-limit" in 
# section [mysqld_safe] 
所有的執行緒開啟表的數量。 
table_cache=256 

# Maximum size for internal (in-memory) temporary tables. If a table 
# grows larger than this value, it is automatically converted to disk 
# based table This limitation is for a single table. There can be many 
# of them. 
臨時表最大記憶體大小。如果一個表生長大於這個值,它會自動轉換為磁碟,這只是限制單個表,可以有很多個 
tmp_table_size=18M 


# How many threads we should keep in a cache for reuse. When a client 
# disconnects, the client's threads are put in the cache if there aren't 
# more than thread_cache_size threads from before.  This greatly reduces 
# the amount of thread creations needed if you have a lot of new 
# connections. (Normally this doesn't give a notable performance 
# improvement if you have a good thread implementation.) 
有很多執行緒我們應該保持在一個快取裡以便重用。在沒有超過超過執行緒快取大小之前,當一個客戶端斷開連線時,把客戶端執行緒放在快取中。如果你有很多新的連線,那麼這大大降低了執行緒的數量創造需要。(如果你有一個好的改進執行緒實現方案,那麼這個並不會給出一個顯著的效能) 
thread_cache_size=8 

#*** MyISAM Specific options 
MYISAM 特殊配置項
 

# The maximum size of the temporary file MySQL is allowed to use while 
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE. 
# If the file-size would be bigger than this, the index will be created 
# through the key cache (which is slower). 
Mysql臨時檔案允許使用重建索引(在修復,修改表結構,匯入資料檔案時)的最大大小。 
如果檔案大小會比這個大,該指數將被建立通過鍵快取(很慢)
 
myisam_max_sort_file_size=100G 

# If the temporary file used for fast index creation would be bigger 
# than using the key cache by the amount specified here, then prefer the 
# key cache method.  This is mainly used to force long character keys in 
# large tables to use the slower key cache method to create the index. 
如果臨時檔案用於快速建立索引將比使用鍵快取更大,那麼鍵快取的方法是很好的。這主要用於在比較大型的表使用緩慢的基礎上,使用長字串建立索引。 
myisam_sort_buffer_size=35M 

# Size of the Key Buffer, used to cache index blocks for MyISAM tables. 
# Do not set it larger than 30% of your available memory, as some memory 
# is also required by the OS to cache rows. Even if you're not using 
# MyISAM tables, you should still set it to 8-64M as it will also be 
# used for internal temporary disk tables. 
在MyISAM表裡用於快取索引塊。不要把它設定為大於你的可用記憶體的30%,因為一些記憶體還需要由OS快取行,即使您沒有使用MyISAM表,您仍然應該將其設定為8 - 64 m,因為它也會用於內部臨時磁碟表 
key_buffer_size=8M 

# Size of the buffer used for doing full table scans of MyISAM tables. 
# Allocated per thread, if a full scan is needed. 
MyISAM表用來做全表掃描的緩衝區大小 
如果需要一個完整的掃描,就分配給每一個執行緒
 
read_buffer_size=64K 
read_rnd_buffer_size=256K 

# This buffer is allocated when MySQL needs to rebuild the index in 
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE 
# into an empty table. It is allocated per thread so be careful with 
# large settings. 
這個緩衝區是分配給:當MYSQL在需要修理,OPTIMZE,修改表結構語句以及匯入載入資料 
到一個空表時重建索引。它是分配給每個執行緒,所以在大型設定中要小心使用。
 
sort_buffer_size=256K 


#*** INNODB Specific options *** 
INNODB特殊項
 
INNODB儲存資料目錄 
innodb_data_home_dir="E:/MySQL Datafiles/" 

# Use this option if you have a MySQL server with InnoDB support enabled 
# but you do not plan to use it. This will save memory and disk space 
# and speed up some things. 
#skip-innodb 

# Additional memory pool that is used by InnoDB to store metadata 
# information.  If InnoDB requires more memory for this purpose it will 
# start to allocate it from the OS.  As this is fast enough on most 
# recent operating systems, you normally do not need to change this 
# value. SHOW INNODB STATUS will display the current amount used. 
InnoDB儲存後設資料資訊時的額外的記憶體池。如果需要更多的記憶體,InnoDB為此它會分配它的作業系統記憶體。因為在大多數作業系統中,這已經是足夠快的了,所以通常不需要修改這個值。SHOW INNODB STATUS會顯示當前的使用量 
innodb_additional_mem_pool_size=2M 

# If set to 1, InnoDB will flush (fsync) the transaction logs to the 
# disk at each commit, which offers full ACID behavior. If you are 
# willing to compromise this safety, and you are running small 
# transactions, you may set this to 0 or 2 to reduce disk I/O to the 
# logs. Value 0 means that the log is only written to the log file and 
# the log file flushed to disk approximately once per second. Value 2 
# means the log is written to the log file at each commit, but the log 
# file is only flushed to disk approximately once per second. 
如果設定為1,InnoDB會在每個提交磁碟沖洗事務日誌,這提供了完整的ACID的行為. 
如果你想安全,並且正在執行一些小操作,你可以設定為0或者2在減少磁碟I / O日誌。
 
#innodb_flush_log_at_trx_commit=1 

# The size of the buffer InnoDB uses for buffering log data. As soon as 
# it is full, InnoDB will have to flush it to disk. As it is flushed 
# once per second anyway, it does not make sense to have it very large 
# (even with long transactions). 
這個大小用於緩衝InnoDB在緩衝日誌資料。一旦它滿了,InnoDB會在磁碟上釋放它。 
它無論如何都會一秒緩衝一次,這對於非常大的日誌是沒有意義的。(即使有長事務)
 
innodb_log_buffer_size=1M 

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and 
# row data. The bigger you set this the less disk I/O is needed to 
# access data in tables. On a dedicated database server you may set this 
# parameter up to 80% of the machine physical memory size. Do not set it 
# too large, though, because competition of the physical memory may 
# cause paging in the operating system.  Note that on 32bit systems you 
# might be limited to 2-3.5G of user level memory per process, so do not 
# set it too high. 
InnoDB,不像MyISAM,使用一個緩衝池來快取的兩個索引和行資料。這個磁碟I / O設定的更大,需要訪問的資料表更少。在專用的資料庫伺服器上你可以設定引數高達80%的機器的實體記憶體大小。不用把它設定的太大,不過,因為在作業系統中競爭的實體記憶體可能導致記憶體不夠分。注意,32位系統上的你可能被限制在2 - 3.5g的使用者級記憶體,所以不要設定的太高。 
innodb_buffer_pool_size=83M 

# Size of each log file in a log group. You should set the combined size 
# of log files to about 25%-100% of your buffer pool size to avoid 
# unneeded buffer pool flush activity on log file overwrite. However, 
# note that a larger logfile size will increase the time needed for the 
# recovery process. 
每個日誌檔案在日誌組裡的大小。你應該將日誌檔案大約為25% - -100%緩衝池大小合併來避免不必要的緩衝池的緩衝行為覆蓋日誌檔案。然而,一個大的日誌檔案將增加復甦過程的所需時間。 
innodb_log_file_size=17M 

# Number of threads allowed inside the InnoDB kernel. The optimal value 
# depends highly on the application, hardware as well as the OS 
# scheduler properties. A too high value may lead to thread thrashing. 
InnoDB的核心允許多執行緒。最高效能取決於高的應用程式、硬體以及作業系統。 
一個很高的值可能導致執行緒抖動
 
innodb_thread_concurrency=8 

總結:Mysql資料庫,分INNODB和MYISAM儲存引擎,MYISAM不支援多執行緒,也就是說,當有一個連結在對某表進行儲存操作的時候,會自動鎖表。當這個連結操作完成以後,後面的連結才能繼續執行儲存操作。而INNODB支援多執行緒,只要不是自己手動鎖表,都不是出現類似MYISAM的情況。然後再查詢速度上,比如:select count(*) from table1;,MYISAM要強於INNODB,因為,在表資料存進來的時候,MYISAM的引擎就會自動儲存一個該表的總數量等資訊,那麼查詢的時候就會自動從那裡取得。一般MYISAM在統計資料時用的比較多,差不多了,我所知有限,如果有錯誤的地方,請各位提出來。
 

相關文章