Innodb配置文件参数调优

——MySQL建议采用MySQL 5.6 InnoDB存储引擎

1.内存利用方面:

innodb_buffer_pool_size ☆☆☆☆☆

Innodb优化首要参数。专用的数据库服务器下需要设置成物理内存的80%大小。不要设置太大,以免因此与操作系统进行分页竞争。注意,在32位系统中,每个进程被限制在2-3.5G,因此不要设置太高。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_buffer_pool_size = 2G)

原文:

#InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and

# rowdata. 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

# toolarge, 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

# setit too high.

innodb_additional_mem_pool_size ☆☆☆☆

用来存放Innodb的内部目录,这个值不用分配太大,系统可以自动调。通常设置16M够用了,如果表比较多,可以适当的增大。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_additional_mem_pool_size = 16M)

原文:

#Additional memory pool that is used by InnoDB to store metadata

#information.  If InnoDB requires morememory for this purpose it will

#start to allocate it from the OS.  Asthis 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.

2.日志方面:

innodb_log_file_size ☆☆☆☆☆

在一个日志组中,每个log的大小。结合innodb_buffer_pool_size设置其大小,25%-100%。避免不需要的刷新。注意:这个值分配的大小和数据库的写入速度,事务大小,异常重启后的恢复有很大的关系。一般取256M可以兼顾性能和recovery的速度

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_log_file_size = 256M)

原文:

#Size of each log file in a log group. You should set the combined size

# oflog 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.

innodb_log_files_in_group☆☆

在一个日志组中,每个log的大小。结合innodb_buffer_pool_size设置其大小,25%-100%。避免不需要的刷新。注意:这个值分配的大小和数据库的写入速度,事务大小,异常重启后的恢复有很大的关系。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_log_files_in_group = 3)

原文:

#Total number of files in the log group. A value of 2-3 is usually good

#enough.

innodb_log_buffer_size ☆☆

日志缓冲区的大小, 默认设置即可,具有大量事务的可以考虑设置为16M

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_log_buffer_size = 8M)

原文:

# Thesize of the buffer InnoDB uses for buffering log data. As soon as

# itis 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_flush_log_at_trx_commit ☆☆☆☆☆

控制log的刷新到磁盘的方式,这个参数只有3个值(0,1,2)默认为1,性能更高的可以设置为0或是2,这样可以适当的减少磁盘IO,游戏库的MySQL建议设置为0

0:log buffer中的数据将以每秒一次的频率写入到log file中,且同时会进行文件系统到磁盘的同步操作,但是每个事务的commit并不会触发任何log buffer 到log file的刷新或者文件系统到磁盘的刷新操作;1:(默认为1)在每次事务提交的时候将logbuffer 中的数据都会写入到log file,同时也会触发文件系统到磁盘的同步;2:事务提交会触发log buffer 到log file的刷新,但并不会触发磁盘文件系统到磁盘的同步。此外,每秒会有一次文件系统到磁盘同步操作。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_flush_log_at_trx_commit = 1)

原文:

# Ifset to 1,InnoDB will flush (fsync) the transaction logs to the

#disk at eachcommit, 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 0means that the log is only written to the log file and

# thelog 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.

3.文件IO和空间占用方面:

innodb_file_per_table ☆☆☆☆☆

使每个Innodb的表,有自已独立的表空间。如删除表后可以回收那部分空间。默认是关闭的,建议打开(innodb_file_per_table=1)

MySQL默认配置文件my-innodb-heavy-4G(无相关设置)

innodb_file_io_threads ☆

文件读写IO数,这个参数只在Windows上起作用。在LINUX上只会等于4,默认即可

MySQL默认配置文件my-innodb-heavy-4G(无相关设置)

innodb_open_files ☆

限制Innodb能打开的表的数据,默认为300,数据库里的表特别多的情况,可以适当增大为1000。innodb_open_files的大小对InnoDB效率的影响比较小。但是在InnoDBcrash的情况下,innodb_open_files设置过小会影响recovery的效率。所以用InnoDB的时候还是把innodb_open_files放大一些比较合适。

MySQL默认配置文件my-innodb-heavy-4G(无相关设置)

innodb_data_file_path ☆☆☆☆☆

指定表数据和索引存储的空间,可以是一个或者多个文件。最后一个数据文件必须是自动扩充的,也只有最后一个文件允许自动扩充。这样,当空间用完后,自动扩充数据文件就会自动增长(以8MB为单位)以容纳额外的数据。例如: innodb_data_file_path=/disk1/ibdata1:900M;/disk2/ibdata2:50M:autoextend两个数据文件放在不同的磁盘上。数据首先放在ibdata1 中,当达到900M以后,数据就放在ibdata2中。建议仿照蜀山的设置。

例如:innodb_data_file_path =ibdata1:1G;ibdata2:1G;ibdata3:1G;ibdata4:1G;ibdata5:1G;ibdata6:1G:autoextend

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_data_file_path = ibdata1:10M:autoextend)

原文:

#InnoDB stores data in one or more data files forming the tablespace.

# Ifyou have a single logical drive for your data, a single

#autoextending file would be good enough. In other cases, a single file

# perdevice is often a good choice. You can configure InnoDB to use raw

#disk partitions as well - please refer to the manual for more info

#about this.

innodb_data_home_dir ☆☆☆

放置表空间数据的目录,默认在mysql的数据目录,设置到和MySQL安装文件不同的分区可以提高性能。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是#innodb_data_home_dir = <directory>)

原文:

# Setthis option if you would like the InnoDB tablespace files to be

#stored in another location. By default this is the MySQL datadir(/var/lib/mysql/).

4.其他相关参数:

innodb_flush_method ☆☆☆☆☆

innodb_flush_log_at_trx_commit确定日志文件何时write/flush,innodb_flush_method则确定日志及数据文件如何write、flush。有三个值,分别是fdatasync,O_DSYNC和O_DIRECT,其中fdatasync是默认值。它们控制了InnoDB刷新日志和数据的模式。O_DIRECT跳过了操作系统的文件系统Disk Cache,直接读写磁盘了。避免双重缓冲,innodb用了innodb_buffer_pool,操作系统层面还有一个缓冲。这样就双重缓冲了,没有必要,反而加大了系统的负载,速度也慢了。可以配置innodb_flush_method = O_DIRECT跳过操作系统的缓冲,直接写入磁盘。建议设置为O_DIRECT

MySQL默认配置文件my-innodb-heavy-4G(中设置的是#innodb_flush_method=O_DSYNC)

原文:

# Theflush method InnoDB will use for Log. The tablespace always uses

#doublewrite flush logic. The default value is "fdatasync", another

#option is "O_DSYNC".

innodb_max_dirty_pages_pct ☆☆

在buffer pool中,允许脏页的百分比,默认为90,建议保持默认。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_max_dirty_pages_pct = 90)

原文:

#Maximum allowed percentage of dirty pages in the InnoDB buffer pool.

# Ifit is reached, InnoDB will start flushing them out agressively to

# notrun out of clean pages at all. This is a soft limit, not

#guaranteed to be held.

 

 

innodb_thread_concurrency ☆☆☆☆☆

同时在Innodb内核中处理的线程数量。建议默认值。

MySQL默认配置文件my-innodb-heavy-4G(中设置的是innodb_thread_concurrency = 16)

原文:

#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.

 

 

公共参数调优

skip-external-locking☆☆

MyISAM存储引擎会使用这个参数,MySQL4.0之后,这个值默认是开启的。作用是避免MySQL的外部锁定(老版本的MySQL此参数叫做skip-locking),减少出错几率增强稳定性。建议默认值。

MySQL默认配置文件my-large.cnf(中设置的是skip-external-locking)

skip-name-resolve ☆☆

禁止MySQL对外部连接进行DNS解析(默认是关闭此项设置的,即默认解析DNS),使用这一选项可以消除MySQL进行DNS解析的时间。但需要注意,如果开启该选项,则所有远程主机连接授权都要使用IP地址方式,否则MySQL将无法正常处理连接请求!如果需要,可以设置此项。

MySQL默认配置文件my-large.cnf(无此项设置)

max_connections ☆☆☆☆

设置最大连接(用户)数,每个连接MySQL的用户均算作一个连接,max_connections的默认值为100。此值需要根据具体的连接数峰值设定。

MySQL默认配置文件my-large.cnf(无此项设置)

query_cache_size ☆☆☆

查询缓存大小,如果表的改动非常频繁,或者每次查询都不同,查询缓存的结果会减慢系统性能。可以设置为0。

MySQL默认配置文件my-large.cnf(query_cache_size= 16M)

sort_buffer_size ☆☆☆☆

connection级的参数,排序缓存大小。一般设置为2-4MB即可。

MySQL默认配置文件my-large.cnf(sort_buffer_size = 1M)

 

read_buffer_size ☆☆☆☆

connection级的参数。一般设置为2-4MB即可。

蜀山中设置的为: (read_buffer_size = 2M)

MySQL默认配置文件my-large.cnf(read_buffer_size = 1M)

 

max_allowed_packet ☆☆☆☆☆

网络包的大小,为避免出现较大的网络包错误,建议设置为16M

MySQL默认配置文件my-large.cnf(max_allowed_packet = 1M)

 

table_cache ☆☆☆☆☆

当某一连接访问一个表时,MySQL会检查当前已缓存表的数量。如果该表已经在缓存中打开,则会直接访问缓存中的表,以加快查询速度;如果该表未被缓存,则会将当前的表添加进缓存并进行查询。(5.1.3之后这个值叫做table_open_cache),通过检查峰值时间的状态值Open_tables和Opened_tables,可以决定是否需要增加table_cache的值。如果发现open_tables等于table_cache,并且opened_tables在不断增长,那么就需要增加table_cache的值。设置为512即可满足需求。

MySQL默认配置文件my-large.cnf(table_open_cache = 256)

 

myisam_sort_buffer_size ☆☆

实际上这个myisam_sort_buffer_size参数意义不大,这是个字面上蒙人的参数,它用于ALTER TABLE, OPTIMIZE TABLE, REPAIR TABLE 等命令时需要的内存。默认值即可。

MySQL默认配置文件my-large.cnf(myisam_sort_buffer_size = 64M)

 

thread_cache_size ☆☆

线程缓存,如果一个客户端断开连接,这个线程就会被放到thread_cache_size中(缓冲池未满),SHOW STATUS LIKE  'threads%';如果 Threads_created 不断增大,那么当前值设置要改大,改到 Threads_connected 值左右。(通常情况下,这个值改善性能不大),默认8即可

MySQL默认配置文件my-large.cnf(thread_cache_size = 8)

 

thread_concurrency ☆☆

线程并发数,建议设置为CPU内核数*2

MySQL默认配置文件my-large.cnf(thread_concurrency = 8)

原文:# Try number of CPU's*2 for thread_concurrency

 

key_buffer_size ☆☆☆☆

仅作用于 MyISAM存储引擎,用来设置用于缓存 MyISAM存储引擎中索引文件的内存区域大小。如果我们有足够的内存,这个缓存区域最好是能够存放下我们所有的 MyISAM 引擎表的所有索引,以尽可能提高性能。不要设置超过可用内存的30%。即使不用MyISAM表,也要设置该值8-64M,用于临时表。

MySQL默认配置文件my-large.cnf(key_buffer_size = 256M)

MySQL配置文件优化(Innodb)的更多相关文章

  1. MySQL · 性能优化· InnoDB buffer pool flush策略漫谈

    MySQL · 性能优化· InnoDB buffer pool flush策略漫谈 背景 我们知道InnoDB使用buffer pool来缓存从磁盘读取到内存的数据页.buffer pool通常由数 ...

  2. 【转载】MySQL · 性能优化· InnoDB buffer pool flush策略漫谈

    背景 我们知道InnoDB使用buffer pool来缓存从磁盘读取到内存的数据页.buffer pool通常由数个内存块加上一组控制结构体对象组成.内存块的个数取决于buffer pool inst ...

  3. mysql性能优化-简易版

    mysql性能优化 sql语句优化 如何发现有问题的sql? 开启mysql慢查询 show variables like 'slow_query_log' set global slow_query ...

  4. mysql数据库优化学习

    目的避免出现页面访问错误慢查询造成页面无法加载阻塞造成数据无法提交优化从sql及索引,数据库结构,系统配置,硬件 日志慢查询日志:   show variables like 'slow_query_ ...

  5. (转)MySQL配置文件mysql.ini参数详解、MySQL性能优化

    本文转自:http://www.cr173.com/html/18331_1.html my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数 ...

  6. MySQL配置文件mysql.ini参数详解、MySQL性能优化

    my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section.  ...

  7. Linux中MySQL配置文件my.cnf参数优化

    MySQL参数优化这东西不好好研究还是比较难懂的,其实不光是MySQL,大部分程序的参数优化,是很复杂的.MySQL的参数优化也不例外,对于不同的需求,还有硬件的配置,优化不可能又最优选择,只能慢慢的 ...

  8. MySQL配置文件my.cnf中文详解附mysql性能优化方法分享

    Mysql参数优化对于新手来讲,是比较难懂的东西,其实这个参数优化,是个很复杂的东西,对于不同的网站,及其在线量,访问量,帖子数量,网络情况,以及机器硬件配置都有关系,优化不可能一次性完成,需要不断的 ...

  9. MySQL配置文件my.cnf参数优化和中文详解

    Mysql参数优化对于新手来讲,是比较难懂的东西,其实这个参数优化,是个很复杂的东西,对于不同的网站,及其在线量,访问量,帖子数量,网络情况,以及机器硬件配置都有关系,优化不可能一次性完成,需要不断的 ...

随机推荐

  1. git之sourceTree使用github和码云的代码小结

    16.使用git出现的错误记录  15. Permission denied (publickey)错误: git远程库与本地库同步 git设置ssh公钥 Bad escape character ' ...

  2. 源码小结:Java 集合ArrayList,LinkedList 源码

    现在这篇主要讲List集合的三个子类: ArrayList 底层数据结构是数组.线程不安全 LinkedList 底层数据结构是链表.线程不安全 Vector 底层数据结构是数组.线程安全 Array ...

  3. c# 数据结构 ArrayList

    数据结构 描述数据之间的关系 行为:添加数据,删除数据,插入数据,查找数据,修改数据 追加数据:向这个结构的末尾添加一个数据 删除数据:在这个结构中删除你指定的数据 插入数据:向这个结构中某一个位置插 ...

  4. Hibernate Criteria使用

    hibernate中Criteria的完整用法 Criteria 是一个完全面向对象,可扩展的条件查询API,通过它完全不需要考虑数据库底层如何实现.SQL语句如何编写,是Hibernate框架的核心 ...

  5. JAVA获取运行程序的src路径

    JavaPrj使用: System.getProperty("user.dir")+"\\src"或直接"\\src"JavaWeb使用Th ...

  6. Python · 进度条

    (这里是本章会用到的 GitHub 地址) 我实现的这个进度条可能是可以当做一个第三方库来使用的(这个人好自大,啧),它支持记录并发程序的进度且损耗基本只来源于 Python 本身 先来看看我们的进度 ...

  7. You Only Look Once: Unified, Real-Time Object Detection

    论文下载:http://arxiv.org/abs/1506.02640  代码下载:https://github.com/pjreddie/darknet Abstract 作者提出一种新的目标检测 ...

  8. ElasicSearch(2) Linux运行

    1.org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearc ...

  9. Ubuntu输入命令无效的问题

    https://blog.csdn.net/u014797226/article/details/80800550?utm_source=blogxgwz2 Ubuntu启动时输入密码后,一直停留在登 ...

  10. Sentinel统计线程,QPS,RT的方式

    一.Sentinel是阿里开源产品,用于流量监控和管理. 二.对于流量控制,可以通过限制线程数和QPS实现限流 1. 资源进入Sentinel的方式 Entry entry = null; try { ...