MySql優化配置

最近做了個小項目,需要對百萬級的數據進行查詢檢索,我用的數據庫是mysql5.6.26,按照網上各種查詢的資料對mysql的配置文件進行了優化,記錄如下,以備不時之需。

修改文件:my-default.ini,下面是這個文件的全部內容,大部分直接摘自於網絡

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.


[mysqld]


skip-name-resolve
max_connections=512


skip-locking #取消文件系統的外部鎖


key_buffer = 512M #索引緩存,根據內存大小而定,如果是獨立的db服務器,可以設置高達80%的內存總量


back_log = 200#連接排隊列表總數


max_allowed_packet = 2M


#打開表緩存總數,可以避免頻繁的打開數據表產生的開銷


table_cache = 512


#每個線程排序所需的緩衝


sort_buffer_size = 4M


#MyISAM表發生變化時重新排序所需的緩衝


myisam_sort_buffer_size = 64M


#緩存可重用的線程數


thread_cache = 128


#查詢結果緩存


query_cache_size = 128M


#最大併發線程數,cpu數量*2


thread_concurrency = 4


#記錄慢查詢,然後對慢查詢一一優化


log_output=FILE # also can be FILE,TABLE or TABLE or NONE


slow-query-log=1


slow_query_log_file=log-slow-queries.log


long_query_time = 1


# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin


# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....




# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.


join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M 


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章