设置日志文件大小
根据经验,设置日志总大小可以保持一个小时左右的服务器活动。
 
 
  
  1. mysql> show global status like 'Innodb_os_log_written';select sleep(60);show global status like 'Innodb_os_log_written'
  2. +-----------------------+-------+ 
  3. | Variable_name         | Value | 
  4. +-----------------------+-------+ 
  5. | Innodb_os_log_written | 3584  | 
  6. +-----------------------+-------+ 
  7. 1 row in set (0.00 sec) 
  8.  
  9. +-----------+ 
  10. | sleep(60) | 
  11. +-----------+ 
  12. |         0 | 
  13. +-----------+ 
  14. 1 row in set (1 min 0.04 sec) 
  15.  
  16. +-----------------------+--------+ 
  17. | Variable_name         | Value  | 
  18. +-----------------------+--------+ 
  19. | Innodb_os_log_written |  19200112 | 
  20. +-----------------------+--------+ 
  21. 1 row in set (0.00 sec) 
  22.  
  23. mysql>  select (19200112-3584)*60 /1024/1204 as MB_PER_HOUR; 
  24. +--------------+ 
  25. | MB_PER_HOUR  | 
  26. +--------------+ 
  27. | 934.21641404 | 
  28. +--------------+ 
  29. 1 row in set (0.00 sec) 

 

MySQL默认使用两个日志文件,设置innodb_log_file_size=500M

 

使用以下方式调整日志文件大小:
 You usually don’t need to change the default number of logs, just the size of each log file. To change the log file size,   shut
down MySQL cleanly, move the old logs away, reconfigure, and restart.  Be sure MySQL
shuts down cleanly, or the log files will actually have entries that need to be applied to
the data files! Watch the MySQL error log when you restart the server. After you’ve
restarted successfully, you can delete the old log files.

 

 

设置日志缓存大小
在innodb改变数据的时候,它会把这次改动的记录写到日志缓冲里面。日志缓冲被保存在内存中。缓冲写满、事务提交或每一秒钟,不管哪种情况先发生,Innodb都会把缓冲区写到磁盘上的日志文件中。如果有大型事务,可以增加innodb_log_buffer_size的大小(默认为8M)来减少I/O动作。不需要把日志缓冲区设置的很大,推荐的设置是1M到8M。除非写入大量的巨型blob记录或大事务,否则这个大小就足够了。
 
  
  1. mysql> show global status like 'Innodb_log_waits'
  2. +------------------+-------+ 
  3. | Variable_name    | Value | 
  4. +------------------+-------+ 
  5. | Innodb_log_waits | 0     | 
  6. +------------------+-------+ 
  7. 1 row in set (0.00 sec) 

 

如果Innodb_log_waits状态变量(等待日志缓冲刷出的次数)的值比较高,而且继续增长,可以增大log buffer或者降低事务大小。
 
innodb_log_file_size与innodb_log_buffer_size的设置需要重启服务器。
 
参考: 高性能MySQL (第二版)