mysql参数总结(更新中)

来源:互联网 发布:smart 改装轮毂数据 编辑:程序博客网 时间:2024/03/29 03:51
innodb_flush_log_at_trx_commit 
0:事务提交时,innodb缓存日志不立即刷盘,而是每秒出发一次缓存日志写盘。
1:事务提交时,立即将数据库日志缓存写到操作系统IO缓存,并立即调用fsync刷新IO缓存,(真正意义上的写盘)。
2:事务提交时,立即将数据库日志缓存写到操作系统IO缓存,但是1秒刷1次IO缓存到磁盘。
2的情况下,数据库崩溃,操作系统未崩溃,数据就不会丢失。这就是区别。

sync_binlog: 
5.7.7版本及以后,默认值由0变成1。很重要的参数。
系统经过sync_binlog次事务提交,才会把事务由内存刷到磁盘。 置为一个比较大的值,如200,500,或者直接不开启,由系统自行决定什么时候刷盘。
否则很拖累系统性能。
该参数与上一个参数有点重复了,个人理解。望大神赐教。

innodb_write_io_threads
innodb写进程数量,默认是4,最大64。更改后需要重启

innodb_flush_method    
这个参数介绍比较多,主要是用于控制刷内存数据到磁盘到底使用什么底层操作系统函数。默认是 fsync.如果数据库写负载很严重,可以尝试更改为 O_direct.

innodb_io_capacity  
动态参数,mysql参考的磁盘IO能力,限制每秒缓冲池加载时每秒最大加载次数。
默认是200,一般的普通盘的IOPS最大也在200左右,For systems with individual 5400 RPM or 7200 RPM drives, you might lower the value to the former default of 100. 如果是7200转以下的机械硬盘,设置该值为100.如果磁盘IOPS很高,可以相应增大。


innodb_log_file_size   在线redo 单个大小
相关参数有 :
innodb_log_group_home_dir = /opt/mysqlfile/logfile   -- redo日志路径
innodb_log_files_in_group = 3                                          -- 日志个数
innodb_log_file_size = 100M                                             --单个日志文件大小

该参数越大,性能越好,但是恢复时需要的时间就越长。权衡下,半小时左右切换一次为佳。
估算日志写入量:
mysql> pager grep -i "Log sequence number" --接下来的显示会被 过滤
PAGER set to 'grep -i "Log sequence number"'
mysql> show engine innodb status\G select sleep(60); show engine innodb status\G
Log sequence number 5038631059    --值 1
1 row in set (0.00 sec)
1 row in set (1 min 0.00 sec)
Log sequence number 5038631059    -- 值 2
1 row in set (0.00 sec)
mysql> nopager
PAGER set to stdout
那么值2-值1 就是日志1分钟增加的KB数,那么就能得到半小时的增量了。我这里由于是测试库,所以日志没怎么增加。

INNODB_LOG_BUFFER_SIZE: 日志缓存区大小
默认是8m,这个参数大小取决于大事物的大小。一个事务操作时,更新或插入的数据要先写到缓冲区上,如果事务过大,就会发生1个事务未完成,但是缓冲区被写满的情况,从而影响性能。如
innodb_flush_log_at_trx_commit =0,那么这个参数对大事务的影响就不会那么大,因为1秒必然发生一次。 保持默认即可。

MAX_CONNECTIONS:最大连接数
先看看这几个状态变量的值:
mysql> show status like '%connection%';
+-----------------------------------+---------------------+
| Variable_name                     | Value               |
+-----------------------------------+---------------------+
| Connection_errors_accept                 | 0                   |
| Connection_errors_internal               | 0                   |
| Connection_errors_max_connections | 0                   |
| Connection_errors_peer_address        | 0                   |
| Connection_errors_select                    | 0                   |
| Connection_errors_tcpwrap                | 0                   |
| Connections                                        | 56988               |
| Max_used_connections                     | 317                 |
| Max_used_connections_time            | 2016-04-20 22:12:27 |
+-----------------------------------+---------------------+
9 rows in set (0.00 sec)
Max_used_connections :历史最高连接数   当前连接数查看为 show status like '%thread%';Threads_connected  为当前连接数。

back_log :
缓冲 连接数,用于处理短时间内大量连接请求的场景。默认值是 50+(max_connnects/5)

table_open_cache
表缓存参数,每一个sql执行线程都要打开一个表缓存。还跟状态变量,opened_table有关,官方文档这样说的,opened_table : The number of tables that have been opened. If Opened_tables is big, your table_open_cache value is probably too small.
测试库开的2000,根据需要调整。

thread_cache_size:为了加快连接速度,定义缓存某些客户服务线程。
根据 状态参数 threads_created 来决定,如果threads_created /connections 接近1,那么说明thread_cache_size 需要增加。

innodb_lock_wait_timeout
单位秒,一个事务等待另外一个事物最长时间。默认50
The length of time in seconds an InnoDB transaction waits for a row lock before giving up. The default value is 50 seconds. A transaction that tries to access a row that is locked by another InnoDB transaction waits at most this many seconds for write access to the row before issuing the following error:
伴随着  
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
报错出现。 意味着 系统正在经历锁等待。需要人工介入查看。





0 0
原创粉丝点击