• 1
  • 2
  • 3
  • 4
  • 5
mysql数据库问题 首 页  »  帮助中心  »  数据库  »  mysql数据库问题
mysql的my.cnf
发布日期:2016-4-26 18:4:53

    一般在MySQL在安装完毕之后,都要对my.cnf进行配置,以得到mysql性能最大化。

  一、关键参数

  通过我们的大宗期货交易平台性能,此配置整理出来,希望你只做一个参照。如图1所示的代码:

  二、innodb_flush_log_at_trx_commit

  Controls the balance between strict ACID compliance for commit operations, and higher performance

  that is possible when commit-related I/O operations are rearranged and done in batches. You can

  achieve better performance by changing the default value, but then you can lose up to a second of

  transactions in a crash.

  • The default value of 1 is required for full ACID compliance. With this value, the contents of the InnoDB

  log buffer are written out to the log file at each transaction commit and the log file is flushed to disk.

  • With a value of 0, the contents of the InnoDB log buffer are written to the log file approximately once

  per second and the log file is flushed to disk. No writes from the log buffer to the log file are performed

  at transaction commit. Once-per-second flushing is not 100% guaranteed to happen every second,

  due to process scheduling issues. Because the flush to disk operation only occurs approximately once

  per second, you can lose up to a second of transactions with any mysqld process crash.

  • With a value of 2, the contents of the InnoDB log buffer are written to the log file after each transaction

  commit and the log file is flushed to disk approximately once per second. Once-per-second flushing

  is not 100% guaranteed to happen every second, due to process scheduling issues. Because the

  flush to disk operation only occurs approximately once per second.

  •   innodb_flush_log_at_trx_commit=1,innodb的缓存会在事务提交或每秒钟时都会进行磁盘的刷新操作,默认值。
  •   innodb_flush_log_at_trx_commit=2,innodb缓存会在提交事务时写入到事务日志但是不会刷新磁盘,然后在每秒钟时进行磁盘刷新操作。
  •   innodb_flush_log_at_trx_commit=0,每秒钟时缓存写入日志,同时刷新磁盘。

  据我们的性能测试发现在innodb_flush_log_at_trx_commit=2,数据的读写速度和1的时候有明显的提升。

  三、innodb_buffer_pool_size、innodb_buffer_pool_instances

  innodb_buffer_pool_size、innodb_buffer_pool_instances这两个参数,你必须得看看这个mysql:提升性能的最关键参数

  四、binlog-format = MIXED

  这种二进制日志模式是statement和row模式的结合体,不过我们需要注意的是mysql 5.7中的默认格式是STATEMENT,这影响服务端代码如Java对事务的处理,非常关键,如果没有调试好的话,要导致事务不回滚。

  In MySQL 5.7, the default format is STATEMENT.

  You must have the SUPER privilege to set either the global or session binlog_format value.

  The rules governing when changes to this variable take effect and how long the effect lasts are the same as for other MySQL server system variables. See Section 13.7.4, “SET Syntax”, for more information.

  When MIXED is specified, statement-based replication is used, except for cases where only row-based replication is guaranteed to lead to proper results. For example, this happens when statements contain user-defined functions (UDF) or the UUID() function. An exception to this rule is that MIXED always uses statement-based replication for stored functions and triggers.

  五、innodb_lock_wait_timeout = 20

  事务回滚的时间间隔,定为20秒,这是我们项目认为比较合理的值,此外可参见Transactional与mysql究竟有什么关系。

  六、transaction-isolation = REPEATABLE-READ

  事务的隔离级别,也对多事务的读写也有着关键的作用,可参见高性能mysql的札记:事务。