my.cnf Parameter Description

MySQL 5.7 database parameter optimization

Connection-related parameters

max_connections: Maximum number of concurrent connections allow the client, the default value is 151, the general parameter is set to 500-2000
the max_connect_errors: If the client tries to connect a number of errors exceeds the value of this parameter is set, the server no longer accept new clients terminal. Such a server may be released to prevent the state of the buffer has a new connection by the host to empty the cache by FLUSH HOSTS or mysqladmin flush-hosts command. The default value for this parameter is 100, the general parameter is set to 100,000.

interactive_timeout: waiting time before the close interaction Mysql connection, in seconds, the default is eight hours, it is recommended not to set the parameters of more than 24 hours, that is 86400

the wait_timeout: Mysql waiting time before closing non-interconnecting, in seconds, the default is 8 hours, not to exceed the recommended parameters for 24 hours, i.e. 86,400

skip_name_resolve: If this parameter is set to OFF, the MySQL service when checking client connections will resolve the hostname; if this parameter is set to ON, the MySQL service will only use IP, in this case, the authorization table Host field must be an IP address or localhost.
This parameter is off by default

back_log: maximum connection queue can handle requests MySQL server connection request, if the queue is filled, the subsequent connection will reject. When the main MySQL thread gets a large number of connection requests in a very short period of time, this parameter will take effect. Next, MySQL main thread will take a short time to check the connection, and then open a new thread. This parameter specifies the MySQL TCP / IP listener queue size. If the MySQL server has a large number of connections in a short time, you can increase this parameter.
File associated parameters sync_binlog: control the binary log to submit the number of groups is synchronized to the binary log before the disk. When this parameter is 0, the binary log is not synchronized to disk; When this parameter is set to 0 or greater value will be set to the binary value of the group to submit periodic synchronization logs to disk. When this parameter is set to 1, all matters before submitting will be synchronized to the binary log, even if the accident MySQL server reboot, the binary log any transactions not only in standby mode, which can lead to MySQL server auto-recovery to roll back the transaction. This will ensure that the binary log is not lost affairs, it is the safest option; at the same time due to increased disk writes, which must reduce performance. This parameter is set to 1 or greater value will improve the performance of the database, but will be accompanied by the risk of data loss. It recommended that this parameter is set to 2,4,6,8,16.

expire_logs_days: binary log automatically deleted interval. The default value is 0, representing the binary log are not automatically deleted. Want to manually delete the binary log, you can perform PURGE BINARY LOGS.

max_binlog_size: The maximum capacity of the binary log file when the binary log writes exceeds this value, it will complete the current binary write, write logs to the new binary log. When the minimum value of this parameter is 4096 bytes; when the maximum and default 1GB. Statement is written with a binary log the same transaction when a transaction is large, the actual size of the binary log exceeds the value max_binlog_size parameter settings. If max_relay_log_size parameter is set to 0, the max_relay_log_size parameters will be used and the same size max_binlog_size parameters. It recommended that this parameter is set to 512M.

local_infile: whether to allow clients to use LOAD DATA INFILE statement. If this parameter is not turned on, clients can not use LOCAL parameter in the LOAD DATA statement.

open_files_limit: operating system allows the number of files opened MySQL services. The actual value of the parameter when starting to set the system value, and table_open_cache max_connections basis, using the following rules:

  1. 10 + max_connections + (table_open_cache * 2)
  2. max_connections * 5
  3. Open_files_limit specified value when starting MySQL

Cache control parameters binlog_cache_size: binary log cache size used in the transaction. If the server supports all MySQL storage engines and binary logging is enabled, each client is assigned a binary log cache. If the database has many large transactions, caching can increase this to get better performance.
Binlog_cache_use and Binlog_cache_disk_use these two parameters for optimization of parameters binlog_cache_size useful. binlog_cache_size parameter setting caching-only firms use non-transactional cache SQL statements used by the binlog_stmt_cache_size control system parameters. It is not recommended this parameter is set to more than 64MB, in order to prevent client connections are many and affect the performance of MySQL services.

max_binlog_cache_size: If a transaction requires more memory than this parameter, the server will complain "Multi-statement transaction required more than 'max_binlog_cache_size' bytes". This parameter is the maximum recommended value is 4GB, because MySQL does not work properly in the case is set to more than 4GB of binary logs. It recommended that the parameters set binlog_cache_size * 2.

binlog_stmt_cache_size: This parameter determines the binary log processing cache non-transactional statements. If the MySQL server supports any transactional storage engine and turn on the binary log, each client connection will be assigned to the binary log transactions and statement caching. If the database is often running large transactions, can increase the cache for better performance.

table_open_cache: all threads can open the number of tables.

thread_cache_size: MySQL server cache to reuse the thread count. When the client disconnects, if not using the thread cache is full, then the client thread is placed in the cache. If you have a client connection is disconnected again after the MySQL service and thread in the cache, the cache of the MySQL service using thread priority; if the thread cache without these threads, the MySQL server creates a new thread. If the database has a lot of new connections, this parameter can be added to improve performance. If the MySQL server has hundreds of connections per second, you can increase thread_cache_size parameters to the MySQL server using cached thread. Connections and Threads_created by checking status parameters can be determined whether sufficient thread cache. This parameter default is determined by the following equation of: 8 + (max_connections / 100)

Recommended to set this parameter is 300 to 500. Thread cache hit rate is calculated as (1-thread_created / connections) * 100%, and can be optimized by adjusting the parameters thread_cache_size this formula.
query_cache_size: cache query results are allocated. By default this parameter is not turned on. This parameter should be set to integer times of 1024, if set to different values will be automatically adjusted to nearly 1024 times this value. This parameter is the minimum required 40KB. Not recommended to set this parameter to system memory is greater than 256MB, so as not to take up too much.

query_cache_min_res_unit: find the best pieces of the size of the allocated buffer. The default value is 4096 (4KB).

query_cache_type: Set the query cache type. When this parameter is 0 or OFF, the MySQL server will not enable query caching; When this parameter is 1 or ON, the MySQL server will cache all query results (in addition to the statement with SELECT SQL_NO_CACHE); When this parameter is 2 or when DEMAND, the MySQL server will cache the statement with SELECT SQL_CACHE.

sort_buffer_size: Each session perform the sort operation allocated memory size. Want to increase max_sort_length parameters, you need to increase sort_buffer_size parameters. If you see the status parameter output Sort_merge_passes SHOW GLOBAL STATUS per second in a large output, it is possible to consider increasing the value sort_buffer_size improve processing speed and a GROUP BY ORDER BY. The recommended setting is 1 ~ 4MB. When the individual sessions need to perform large sort operations, increase this parameter at the session level.

read_buffer_size: memory that is allocated to the execution order read MyISAm table for each thread. If there is a database of sequence read, can increase this parameter, the default value is 131,072 bytes. The value of this parameter needs to be an integer multiple of 4KB. This parameter is also used in the following scenarios:

  • When performing ORDER BY operations, a cache index to a temporary file (not the temporary table);
  • A bulk inserted into the partition table;
  • Cache nested query execution results.

read_rnd_buffer_size: This parameter is used in the table and any memory storage engine MyISAM random read table used. When reading data from the key MyISAM table to sort scanned rows using this cache to avoid scanning disk. This value is set to a large value can significantly improve the performance of ORDER BY. Then, this parameter will be applied to all client connections, all the parameters should not be set to a large value at the global level; in the session run large queries, at the session level increase this parameter.

join_buffer_size: the MySQL server is used as a common index scan, and the range of index scan is performed without using an index buffer size full table scan used in these operations. Typically, the fastest way to get connected is to increase the index. When the index is not increased when the method is fully connected faster increase join_buffer_size parameters. Two tables for the implementation of fully connected, each table is assigned a memory connection. For multi-table without using complex indexing connector, connecting a plurality of memory required. Generally speaking, this parameter may be a smaller value on the global, in the session need to perform a large set connected at the session level. The default value is 256KB.

net_buffer_length: Each client connection threads and cache and cache the results of interaction, each cache size is assigned initially to net_buffer_length capacity, and dynamic growth until it reached the size of max_allowed_packet parameters. After each SQL statement is finished, the result will be reduced to net_buffer_length cache size. Not recommended to change this parameter unless your system has very little memory, you can adjust the parameters. If the statement requires more memory than the size of this parameter, the connection cache will automatically increase. net_buffer_length maximum parameter can be set to 1MB. This parameter can not be set at the session level.

max_allowed_packet: size of a single packet transmission network. The default is 4MB. But the package is likely to grow to a value of max_allowed_packet parameters set by the initial value of the package cached information is specified by the net_buffer_length. If you are using long strings or BLOB field is necessary to increase the value of this parameter. This parameter is required to be provided and BLOB fields as the maximum size. protocol parameter max_allowed_packet limit is 1GB. This argument should be an integer multiple of 1024.

bulk_insert_buffer_size: MyISAM table uses a special batch tree cache to improve the speed of insertion, such as INSERT ... SELECT, INSERT ... VALUES ( ...), (...), ..., empty table execution LOAD DATA INFILE. This parameter tree cache size for each thread. Setting this parameter to 0 disables this parameter. The default value for this parameter is 8MB.
max_heap_table_size: This parameter sets MEMORY table allows the user to create maximum capacity growth, the value of this parameter is used MAX_ROWS MEMORY table. Setting this parameter has no effect on existing MEMORY table, unless the table to rebuild or execute ALTER TABLE, TRUNCATE TABLE statement.

This parameter can also take a size parameter and tmp_table_size internal in-memory tables now. If the memory table use frequently, you can increase the value of this parameter.

tmp_table_size: Maximum Memory Internal memory temporary tables. This parameter does not apply to MEMORY table created by users. If the size of the memory temporary table exceeds this value of the parameter, then MySQL will automatically excess is converted into temporary tables on disk. In MySQL 5.7.5 version, internal_tmp_disk_storage_engine engine as the default storage engine disk temporary tables. In previous versions of MySQL 5.7.5, it will use the MyISAM storage engine. If there are many GROUP BY query system and ample memory, consider increasing this parameter.

innodb_buffer_pool_dump_at_shutdown : specified when the MySQL service shutdown, whether InnoDB buffer pool cache page record, in order to shorten the warm-up process at the next restart. Usually innodb_buffer_pool_load_at_startup parameters with use. innodb_buffer_pool_dump_pct parameter defines the percentage of recently used cached pages reserved.

innodb_buffer_pool_dump_now: Immediately records cached pages InnoDB buffer pool. Usually innodb_buffer_pool_load_now with use.

innodb_buffer_pool_load_at_startup: Specifies the MySQL service when you start, InnoDB buffer pool cache page by automatically preheat data before loading. Usually innodb_buffer_pool_dump_at_shutdown parameters with use.

innodb_buffer_pool_load_now: immediately to preheat the InnoDB buffer pool by loading the data page, without having to restart the database service. Can be used in the performance test, the cache will change to a known state; or after you run the report database queries or maintenance, the database will be changed to a normal state.
MyISAM parameters key_buffer_size: All common thread MyISAM table index cache, this cache is used index blocks. Increasing this parameter may increase read and write performance index, the system is mainly used MyISAM storage engines, this parameter can be set to 25% of the total memory of the machine. If this parameter is set very large, for example, is set to more than 50% of the total memory of the machine, the machine will start to page and become extremely slow. You can view Key_read_requests, Key_reads, Key_write_requests, and Key_writes these status values SHOW STATUS statement. Normally Key_reads / Key_read_requests ratio should be less than 0.01. Frequent database updates, and deletes time, Key_writes / Key_write_requests ratio should be close to 1.

key_cache_block_size: block size of the cache key, the default value is 1,024 bytes.

myisam_sort_buffer_size: In REPAIR TABLE, CREATE INDEX or ALTER TABLE operation, MyISAM index ordering buffer size used.

: myisam_max_sort_file_size maximum capacity when rebuilding MyISAM indexes, such as performing REPAIR TABLE, ALTER TABLE, or LOAD DATA INFILE command, MySQL allows the use of temporary files. If MyISAM index file exceeds this value, and there is plenty of disk space, increase this parameter helps improve performance.

myisam_repair_threads: If the value of the parameter is greater than 1, then the sorting process performed in MyISAM table Repair operation, when creating the index will enable parallel, the default value is 1.
InnoDB parameters innodb_buffer_pool_size: Memory cache table storage engine InnDB size and index data is used. The default is 128MB. In order InnDB storage engine based system, this parameter can be set to 80% of the machine physical memory. Also note:

  • Will switching engine pages and degraded performance when setting up large physical memory;
  • InnoDB storage engine of the memory used as a cache control table and configuration information, so the actual cost may be greater than 10% of memory than the set value;
  • The larger this parameter is set, the longer the memory pool initialization time. In MySQL 5.7.5 version, you can increase or decrease the size of the chunk of memory pool of units. The chunk size can be innodb_buffer_pool_chunk_size parameter setting, the default value is 128MB. Memory pool size may be equal to or an integer multiple innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances.

innodb_buffer_pool_instances : Number InnoDB buffer pool area is divided. For more than 1GB of large InnoDB cache, the cache is divided into multiple parts can improve concurrency MySQL services, reduce competition different threads to read and write cache page read. Each has its individual buffer pool free list, refresh the list, the data structure of the LRU list and the other connected to the memory pool, which are protected mutex lock. This parameter will only innodb_buffer_pool_size parameter is set to take effect only 1GB or more. It recommended that each divided region is set to 1GB memory size.

innodb_max_dirty_pages_pct: when the percentage of dirty page cache pool Innodb share reached a value of this parameter, InnoDB will write data to the disk from the cache. The default value is 75.
innodb_thread_concurrency: InnoDB storage engine can be complicated by the maximum number of threads used. When the thread InnoDB exceeds the value of this parameter, the latter thread enters a wait state, the first in first out algorithm to process. Threads wait for a lock is not included in the value of the parameter. This parameter is the range 0 to 1000. The default value is 0. When this parameter is 0, the number of concurrent threads on behalf of InnoDB is not limited, this will cause MySQL to create as many threads as it needs. This parameter can be set with reference to the following rules:

  • If the number of concurrent users is smaller than the threads 64, this parameter can be set to 0;
  • If the system is complicated by severe, the first parameter is set to be 128, then this parameter will be reduced gradually to 96, 80, 64 or other value, until it finds a better performance value.

innodb_flush_method: data to InnoDB data files and log files of the methods specified refresh, refresh method would be I / O impact. If this parameter is empty, on Unix-like systems, the fsync default value for this parameter; on Windows systems, the default parameter is async_unbuffered. On Unix systems, the value of this parameter can be set as follows:

  • fsync: InnoDB use fsync () system function to refresh the data and log files, fsync is the default parameter.
  • O_DSYNC: InnoDB use O_SYNC function to open and flush the log file, use the fsync () function to refresh the data file
  • littlesync: This option is used to test the internal performance of the current MySQL does not yet support the use of this parameter and some risk
  • nosync: This option is used to test the internal performance of the current MySQL does not yet support the use of this parameter and some risk
  • O_DIRECT: InnoDB use O_DIRECT (or directio () in Solaris) function to open the data file, use fsync () to refresh the data files and log files
  • O_DIRECT_NO_FSYNC: When you refresh I / O, InnoDB use O_DIRECT way.

On systems with RAID card and write cache in, O_DIRECT help avoid double buffer between the InnoDB buffer pool cache and operating system. SAN storage system on top of the data and log files in InnoDB, default or read-mostly O_DSYNC method will accelerate through the database.
innodb_data_home_dir: physical path InnoDB file system table data space used, the default path is MySQL data file path. If this parameter is empty, you can use an absolute path parameters in innodb_data_file_path

innodb_data_file_path: Path and size InnoDB data files.

innodb_file_per_table: When this parameter is enabled, InnoDB will create a new table and index data stored in a separate file .ibd format, rather than stored in the system table space. When this table is deleted or TRUNCATE, InnoDB table occupied storage will be released. Some other features of this set will open InnoDB, such as compression of the table. When this parameter is closed when, InnoDB tables and indexes data will be stored in the file system ibdata table space, this will be a problem, because the system table space will not shrink, this setting can result in space can not be played back.

innodb_undo_directory: physical path where InnoDB undo log tablespace. And innodb_undo_logs, innodb_undo_tablespaces parameter fit to undo log set the path, the default path is a data file path.

innodb_undo_logs: Specifies the number of used InnoDB undo log. In MySQL 5.7.2 version 32 is temporarily undo log tables reserved for future use, and the logs stored in the temporary table entry space (ibtmp1) in. If only undo log table stored in the system space allocated for the desired additional data modification with undo transaction log, innodb_undo_logs parameter must be set to an integer of 32 or more. If you configure separate undo table space, to innodb_undo_logs parameter is set to allocate more than 33 extra for data modifications undo the transaction logs used. Each undo log can support up to 1024 transactions. If this parameter is not set, it will be set to the default value of 128.

innodb_undo_tablespaces: the number of table space file undo log. By default, all logs are part of the system undo table space. Because when you run a large transaction, undo logs will increase, will undo log settings in more than one table space can reduce the size of a table space. undo tablespace files created in innodb_undo_directory parameter specifies the path named undoN format, N is an integer number beginning with 0. The default size of the undo table space is 10M. Innodb_undo_tablespaces need to set this parameter before initiating InnoDB. In MySQL 5.7.2 version, the undo log 128, undo log 32 is reserved for temporary tables, there are 95 undo log for undo tablespace.

innodb_log_files_in_group: log log number InnoDB group contains. InnoDB in a cyclical fashion logged. The default and recommended value for this parameter are 2. Innodb_log_group_home_dir path of the log is set by parameters.

innodb_log_group_home_dir: the InnoDB physical path redo log file, specified by the number of redo logs innodb_log_files_in_group parameters. If you do not specify any InnoDB log parameters, the default MySQL will create two named ib_logfile0 in the MySQL data file path below, ib_logfile1 two redo log files, their size parameters set by innodb_log_file_size.

the innodb_log_file_size : log file size in bytes of each log group. All log file size (innodb_log_file_size * innodb_log_files_in_group) can not exceed 512GB.

innodb_log_buffer_size: InnoDB disk write cache size in bytes of log file to be used. If the parameter is innodb_page_size 32K, the default value is 8MB; innodb_page_size if the parameter is 64K, then the default is 16MB. If the log is set larger cache, MySQL when large transactions are processed before committing the transaction log files do not need to be written to disk. This parameter is recommended to set 4 ~ 8MB.

innodb_flush_log_at_trx_commit: When submit an I / O operation are rearranged batches, this parameter to control the balance between the high performance and consistency ACID commit operation. You can change the default value of the parameter to improve database performance, but when the database is down will lose a small amount of the transaction. The default for this parameter is 1, representing full ACID compliance database model, whenever a transaction commits, the content of InnoDB log buffer will be flushed to the log file and write to the disk. When this parameter is 0, InnDB log cache refresh every second about the log file to disk. When the transaction commits, the log buffer is not written to the log file at once, such a mechanism does not guarantee 100% every second refresh log to a log file, when mysqld process dawdle out, they might lose a duration of about 1 second transaction data. When this parameter is 2, when the transaction is committed, the content of InnoDB log buffer is written to the log file and log files, log files about once a second flushed to disk. In the version of MySQL 5.6.6, InnoDB log refresh frequency is determined by innodb_flush_log_at_timeout parameters. The usual argument is set to 1.

innodb_flush_log_at_timeout: write or refresh interval log. This parameter was introduced in MySQL version 5.6.6. Prior to MySQL 5.6.6 version, refresh frequency is refreshed once per second. The default value of the parameter is 1 second innodb_flush_log_at_timeout refresh.

innodb_lock_wait_timeout: the length of time InnDB waiting for row lock transaction. The default is 50 seconds. When a transaction locks the row, then another transaction wants to access and modify this line, when the waiting time reaches the value innodb_lock_wait_timeout parameter settings, MySQL will get an error "ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction", and it will rollback statement (not roll back the entire transaction). If you want to roll back the entire transaction, use --innodb_rollback_on_timeout parameter to start MySQL. On highly interactive applications or OLTP system, this parameter can be reduced to quickly display the user's feedback or update a queue for later processing. In the data warehouse, for better operation of the processing operation for a long time can be increased this parameter. This parameter is only used in InnoDB row lock, this parameter is not valid for table-level locking. This argument does not apply to a deadlock, because when a deadlock occurs, InnoDB will immediately detect deadlocks and a deadlock transaction rollback.

innodb_fast_shutdown: InnoDB off library mode. If this parameter is 0, InnoDB will do a slow shutdown, before the shutdown will do a complete refresh operation, this level of library operations off for a few minutes, when the amount of data in the cache is large, even for several hours ; If the database to perform a version upgrade or downgrade, you need to perform this level of clearance library operations, to ensure that all data changes are written to the data file. If this parameter is 1 (the default value), in order to save libraries time off, InnoDB will skip the new operation, but the refresh operation the next time you boot through crash recovery mode. If this parameter is 2, InnoDB will refresh with cold way off the log and database downtime as MySQL, like, the transaction will not have to be lost, the next time you open the database, the crash recovery time needed for longer; in an emergency under or troubleshooting situations, immediately shut down the database when needed, it will be used in this way stop library.

Guess you like

Origin www.cnblogs.com/h-gallop/p/11645899.html