Mysql Optimization - typical server configuration

 

Memory configuration parameters

 

  mysql memory allocation needs to take into account the need to use the operating system memory, memory, memory for other applications to be used, number of sessions, and each session using mysql, and then is the memory used by the operating system instance. mysql production environment often is an instance of a service exclusively, therefore, need to consider a few examples of mysql mysql session, the session memory and memory instance.

 

  Session parameter memory corresponding to the size of memory allocated for each connection session, the main parameters associated has the following:

  It will be assigned a size corresponding to one-time cached statement sent by the session need to be sorted: sort_buffer_size

  join_buffer_size: Applications often some two tables (or table) join the operational requirements, Mysql (all / index join), in order to reduce participation join the "table driven" number of reads in the completion of some join the demand of time to improve performance, we need to join buffer to help complete the join operation. When the buffer is too small join, mysql not the buffer to disk files, but the first results set of join in the buffer needs to join the table join operation is performed, and then clears the data buffer of the join, the remaining set of results continue written in this buffer, and so forth, will cause the drive table needs to be read many times, multiplied IO access, reducing efficiency.

  read_buffer_size: mysql read into the buffer size. Request table for assigning a sequential scans read into the buffer, mysql allocate some memory buffer for him. read_buffer_size variable controls the size of the buffer. If the request for a sequential scan of the table very often, and you said it was slow scan frequently, it can improve its performance by increasing the memory and variable buffer size.

  read_rnd_buffer_size: mysql random read buffer size. When reading a row in any order (e.g., sorted order), assigning a random read buffer. When sorting query, mysql will first scan it again this buffer to avoid disk seeks, speed up the search, if needed sorting large amounts of data, it should adjust the value. But mysql will release the buffer space for each client connection, it should be possible to set the appropriate value to avoid memory overhead is too large.

  Innodb_buffer_size: InnoDB use this parameter to specify the size of the memory to buffer the data and index, this is the most influential InnoDB engine performance parameters

  key_buffer_size: myisam determines the speed of the indexing process, particularly in the index reading speed. The default is 16M, value key_read_requests (number of requests to read the index from the cache) by checking the status and key_reads (read from the disk index number of requests), you can know key_buffer_size set is reasonable. Ratio key_reads / key_read_requests should be as low as possible, it is at least 1: 100, 1: 1000 better (SHOW STATUS LIKE 'key_read%'). key_buffer_size only work for MyIsam table. Even if you do not use MyIsam table, but the internal temporary disk tables are MyIsam table, but also to use that value. The set value of the size may be obtained by the following statement.

  select sum(index_length) from information_schema.tables where engine='myisam';

 

IO configuration parameters

  innodb parameters

  The size of this value redo log file: innodb_log_file_size

  innodb_log_files_in_group: The number of the redo log file set value

  innodb_log_buffer_size: the size of the redo log buffer pool

  innodb_flush_log_at_trx_commit: This parameter sets the mysql redo log to refresh the way the log file. This parameter has the following three values:

  0: data every second mysql will redo log buffer is flushed to the operating system cache, and flushed to disk, but does not cause any transaction commit operation. This will lose at least 1 second of data.

  1: Perform at every transaction commit log written to cache, and the data is flushed to disk (default)

  2: when the transaction will be submitted to refresh the data cache operating system, but does not cause data flushed to disk, in this mode, mysql executes every second flushed to disk operations, so there is likely to cause system crashes 1s of data loss.

  When set to 0, the fastest model, but less secure, mysqld process crash can cause the loss of the last second of all transaction data. Is set to 1, the mode is the most secure, but also the slowest way. In the case mysqld server to crash or crash the server host, binary log may be missing at most only a statement or a transaction. Is set to 2, the mode faster than 0 security, only an operating system crash or power failure at the system, the data will be lost on one second (ranging between 0 and 1)

  innodb_flush_method: This parameter controls the innodb data files and redo log is open, flashing mode. There are three values: fdatasync (default, call fsync () to brush the redo log file data buffer), O_DSYNC, O_DIRECT

  innodb_double_write: double write buffer, the cache is used to protect the data block to avoid data corruption when the write block

 

  MyIsam parameters

  delay_key_write: refers to the table before the close, update the operating table will be updated only data to disk, without updating the index to disk, the changes to the index in memory

 

Security-related configuration parameters

  expire_log_days: binary log specified number of days reserved

  skip_name_resolve: Disable DNS lookup

  read_only: database read-only mode to

  skip_slave_start:mysql启动后不会启动主从复制

 

其他配置

  sync_binlog:同步二进制日志的频率,设置0的表示 mysql 不控制 bin log的刷新, bin log 日志刷新到磁盘完全依赖于文件的操作系统,这时候的性能是最好的,但是风险也是最大的。当设置为 n 时,指每个 N 次操作时进行磁盘同步,这里将磁盘设置为1是最安全的设置,但是刷新的频率过高对 IO 的影响也非常大。

  tmp_table_size:规定了内部内存临时表的最大值,每个线程都要分配,如果内存临时表超出了限制,mysql 就会自动地把它转化为基于磁盘的 MyIsam表,存储在指定的 tmpdir 目录下

  max_heap_table_size:这个变量定义了用户可以创建的内存表(memory table)的大小,这个值用来计算内存表的最大行数值。这个变量支持动态改变,即 set @max_heap_table_size = xxx,但是对于已经存在的内存表就没有什么用,除非这个表被重新创建或者修改或者 truncate table,服务重启也会设置已经存在的内存表为全局 max_heap_table_size 的值。这个参数和 tmp_table_size 一起限制了内部内存表的大小

  max_connections:设置 mysql 会话连接的最大值

 

Guess you like

Origin www.cnblogs.com/lili-xia/p/11325703.html