您的位置:首页 > 数据库 > MySQL

MySql优化配置

2015-11-03 10:42 507 查看
最近做了个小项目,需要对百万级的数据进行查询检索,我用的数据库是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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: