Configure MySQL Performance Tuning

purpose

For different business scenarios, by adjusting the parameters of the database configuration can effectively improve server performance.

method

Using the following profile parameters to start the database, the default configuration file path /etc/my.cnf, wherein the data storage and software installation MySQL path modification according to the actual situation.

[mysqld_safe]
log-error=/data/mysql/log/mariadb.log
pid-file=/data/mysql/run/mysqld.pid

[client]
socket=/data/mysql/run/mysql.sock
default-character-set=utf8

[mysqld]
basedir=/usr/local/mysql
tmpdir=/data/mysql/tmp
datadir=/data/mysql/data
socket=/data/mysql/run/mysql.sock
port=3306
user=root
default_authentication_plugin=mysql_native_password
Close ssl ssl = 0 #
max_connections = 2000 # Set the maximum number of connections
back_log = 2048 # Set the number of session request cache
performance_schema = OFF # closing performance mode
max_prepared_stmt_count=128000

#file
innodb_file_per_table # Set a file for each table
innodb_log_file_size = 1500M # Set size logfile
innodb_log_files_in_group = 32 Group Number # Set logfile
innodb_open_files = 4000 # set the maximum number of open tables

#buffers
innodb_buffer_pool_size = 230G # Set buffer pool size, generally 60% server memory
innodb_buffer_pool_instances = 16 # set the number of buffer pool instance, to improve concurrency
innodb_log_buffer_size = 64M # Set the size of log buffer size

#tune
sync_binlog = 1 # Set each transaction commit brush disc sync_binlog
innodb_flush_log_at_trx_commit = 1 # MySQL will put each log buffer data is written when the transaction is committed log file, and flush (brush to disk) go
innodb_use_native_aio = 1 # open asynchronous IO
innodb_spin_wait_delay = 180 # spin_wait_delay parameter set to prevent entering of spin
Set spin_loops innodb_sync_spin_loops = 25 # cycles, to prevent entering of spin
innodb_flush_method = O_DIRECT # Set innodb and redo log data file is opened in write mode brush
innodb_io_capacity = 20000 # innodb background thread to set maximum limit per iops
innodb_io_capacity_max = 40000 # iops maximum limit innodb background thread per second under a pressure
innodb_lru_scan_depth = 9000 # settings page cleaner threads each brush number of dirty pages
The number of threads innodb_page_cleaners = 16 # Set the dirty data is written to disk

#perf special
innodb_flush_neighbors = 0 # All pages of the page where the detection zone (extent) if the page is dirty, then the refresh together, the SSD disable this feature
innodb_write_io_threads = 16 # Set the number of threads to write
innodb_read_io_threads = 16 # set the number of read threads
Number innodb_purge_threads = 32 # Set the recovery has been used and allocated page thread undo

sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_AUTO_VALUE_ON_ZERO,STRICT_ALL_TABLES
 

parameter name

Parameter Meaning

Optimization Tips

innodb_thread_concurrency

InnoDB uses the operating system threads to handle the transaction request from the user.

Recommendations from the default value of 0, which indicates not limit the number of concurrently executing threads by default.

innodb_read_io_threads

Execution request queue of the read operation request to the number of threads.

CPU core count and read and write according to the proportion of further changes to improve performance.

innodb_write_io_threads

Write queue threads to perform the requested operation request.

CPU core count and read and write according to the proportion of further changes to improve performance.

query_cache_size

Set query_cache_size size.

Query Cache (query cache) is a well-known bottleneck position, it will appear even when the amount of concurrency is not high. The best option is to disable it from the outset. By setting query_cache_size = 0, recommends disabling the query cache.

innodb_buffer_pool_instances

Open plurality of memory pools, the need to buffer data into different hash buffer pool, which can read and write memory in parallel.

8 to 16 is recommended to set.

innodb_open_files

In innodb_file_per_table mode, limit the number of files that can be opened Innodb.

This value is recommended to transfer large number, especially multi-table special circumstances.

innodb_buffer_pool_size

Local cache data and indexes.

Memory is generally recommended around 70%.

innodb_log_buffer_size

Cache redo logs.

The default value is 64M, recommended by looking innodb_log_wait, adjust innodb_log_buffer_size size.

innodb_io_capacity

innodb background thread iops per second maximum limit.

Recommendations for 75% IO QPS total capacity.

innodb_log_files_in_group

The number of redo log groups.

-

innodb_log_file_size

Redo log file size.

If there are a large number of write operations, it is recommended to increase the log file size, but the log file is too large, it will affect data recovery time.

If a non-production environment, testing the limits performance, try to transfer large log files.

If a commercial scene, consider data recovery time, set the log file size after a comprehensive compromise.

innodb_flush_method

Log and data refresh method disks:

  1. datasync mode: When writing data, write this step does not need to actually written to the disk is not complete (probably written to the buffer in the operating system will return to complete), is truly complete flush operation, buffer to the operating system to flush, and metadata information files also need to be updated to disk.
  2. O_DSYNC mode: written log operation is completed this step in write, and write data files is accomplished by fsync in flush this step.
  3. O_DIRECT mode: write data files from mysql innodb buffer directly to disk, the operating system does not use a buffer, but also in the flush truly complete this step, or to go through the OS log buffer.

We recommend O_DIRECT mode.

innodb_spin_wait_delay

Polling control interval.

According to debug real scene until no splin_lock hotspot function and so on.

innodb_sync_spin_loops

The number of polling control illusory.

According to debug real scene until no splin_lock hotspot function and so on.

innodb_lru_scan_depth

The number of available pages LRU list.

The default value is 1024, non-production environment, test limits performance can be adjusted appropriately large, reduce the number of checkpoint.

innodb_page_cleaners

Refresh number of threads dirty data.

Suggestions and equal innodb_buffer_pool_instances.

innodb_purge_threads

The number of threads undo the recovery.

-

innodb_flush_log_at_trx_commit

  • 0: whether or not to submit, every second written binlog log.
  • 1: Every time a transaction is committed, the contents of the log buffer will be written to disk to go, the log files do disk flushing, the best security.
  • 2: Every time a transaction is committed, are written to the operating system cache, refreshed by the OS to the disk, the best performance.

Non-production environment, test performance limits can be set to 0.

innodb_doublewrite

Whether to open the second write.

非生产环境,测试极限性能,可以设置为0,关闭二次写。

ssl

是否开启安全连接。

安全连接对性能影响较大,非生产环境,测试极限性能,可以设置为0;商用场景,根据客户需求调整。

skip_log_bin

是否开启binlog。

非生产环境,测试极限性能在参数文件中增加此参数,关闭binlog选项。

innodb_checksum_algorithm

数据完整性校验。

非生产环境,测试极限性能设置成none,不启用算法校验。

binlog_checksum

Binlog完整性校验。

非生产环境,测试极限性能设置成none,不启用算法校验。

innodb_log_checksums

Log完整性校验。

非生产环境,测试极限性能设置成0,关闭log checksum。

foreign_key_checks

外键校验。

非生产环境,测试极限性能设置成0,关闭外键校验。

performance_schema

是否开启性能模式。

非生产环境,测试极限性能设置为OFF,关闭性能模式。

Guess you like

Origin www.cnblogs.com/myzan/p/12659461.html
Recommended