MySQL configuration file my.cnf parameter optimization in Linux

Source: Internet
Author: User
Tags bulk insert create index mysql client

MySQL parameter optimization this thing is not well researched or more difficult to understand, in fact, not only MySQL, most of the program parameters optimization, is very complex. MySQL parameter optimization is no exception, for different requirements, there are hardware configuration, optimization is not possible and optimal choice, only slowly optimize, need constant debugging, in order to achieve the best choice of different environments.

Let's start by introducing the different modules in the MySQL configuration file

[Client] MySQL client application module, only the client application included with MySQL guarantees that the content under this module can be read.
[Mysqld] MySQL service-side application module
[Client]Port=3306Socket=/tmp/Mysql.sock[mysqld]User= MySQL---the Admin user port that represents MySQL=3306---Port Socket=/tmp/mysql.sock--Startup sock File log-bin =/data/mysql-Binbasedir=/usr/local/Mysqldatadir=/data/PID-file=/data/Mysql.piduser=Mysqlbind-address =0.0.0.0Server-ID=1#表示是本机的序号为1, generally speaking, is the meaning of master skip-name-resolve# Disables the DNS parsing of external connections by MySQL, and using this option can eliminate the time for DNS resolution for MySQL. Note, however, that if this option is turned on, all remote host connection authorizations must use IP address, otherwise MySQL will not be able to handle connection requests properly #skip-Networkingback_log= -# Number of connections MySQL can have. When the primary MySQL thread gets very many connection requests in a very short time, this works, # then the main thread takes some time (albeit very short) to check the connection and start a new thread. The Back_log value indicates how many requests can be present in the stack for a short period of time before MySQL temporarily stops answering a new request. # If you expect to have a lot of connections in a short period of time, you need to add it. That is, if the MySQL connection data reaches max_connections, the new request will be present in the stack, # to wait for a connection to release the resource, the number of that stack is back_log, and if the number of waiting connections exceeds back_log, the connection resource will not be granted. # In addition, this value (Back_log) is limited to your operating system on incoming TCP/The size of the listening queue for the IP connection. # your operating system has its own limit on this queue size (you can check your OS documentation to find out the maximum value of this variable), trying to set the limit of Back_log above your operating system will be invalid. Max_connections= +# mysql Maximum number of connections, if the server's concurrent connection request volume is larger, it is recommended to increase the number of concurrent connections, of course, this is based on the machine can support the case, because if the number of connections between MySQL will provide a connection buffer for each connection, it will cost more memory, Therefore, to adjust the value appropriately, you can not blindly increase the value set. Can over'conn%'Wildcards View the number of connections in the current state to decide the size of the value. Max_connect_errors=6000# for the same host, if there is an interrupt error connection that exceeds the number of values for this parameter, the host will be blocked from connecting. To unblock the host, execute: FLUSH host. Open_files_limit=65535# mysql Open file descriptor limit, default minimum 1024; When Open_files_limit is not configured, compare Max_connectionsand Ulimit-the value of N, which is the big one, # when OPEN_FILE_LIMIT is configured, compare Open_files_limit and Max_connections*the value of 5, which is the big one. Table_open_cache= -# MySQL Every time you open a table, it will read some data into the Table_open_cache cache, and when MySQL cannot find the appropriate information in this cache, it will go to the disk to read. The default value 64# assumes that the system has 200 concurrent connections, you need to set this parameter to*N (n is the number of file descriptors required for each connection); # when the Table_open_cache is set to a large size, if the system does not handle so many file descriptors, then the client fails, and the connection is not max_allowed_packet=The size of the packet accepted by the 4m#; it is safe to increase the value of this variable because additional memory is allocated only when needed. For example, MYSQLD will allocate more memory only if you issue a long query or if mysqld must return a large result row. # This variable takes a smaller default value as a precaution to capture error packets between the client and server, and to ensure that memory overflows are not caused by accidental use of large packets. Binlog_cache_size=1m# a transaction that, when not committed, logs the resulting log to the cache, and persists the log to disk when the transaction submission needs to be committed. Default Binlog_cache_size size 32kmax_heap_table_size=8m# defines the size of memory table that users can create. This value is used to calculate the maximum row value for the memory table. This variable supports dynamic change of tmp_table_size=16m# MySQL heap (heap) table buffer size. All unions are completed within a DML instruction, and most unions can be done without a temporary table. # Most temporary tables are memory-based (HEAP) tables. Temporary tables with large record lengths (the and the length of all columns) or tables containing BLOB columns are stored on the hard disk. # If an internal heap (stacked) table is larger than Tmp_table_size,mysql, you can automatically change the in-memory heap table to the hard disk-based MyISAM table as needed. You can also increase the size of the staging table by setting the Tmp_table_size option. In other words, if this value is raised, MySQL will increase the size of the heap table, which can improve the speed of the join query Read_buffer_size=2m# MySQL read-in buffer size. A request to sequentially scan a table allocates a read-in buffer, and MySQL allocates a memory buffer for it. The read_buffer_size variable controls the size of this buffer. # If the sequential scan requests to the table are very frequent and you think that frequent scans are going too slowly, you can improve their performance by increasing the value of the variable and the size of the memory buffer read_rnd_buffer_size=8m# MySQL's random read buffer size. When rows are read in any order (for example, in sort order), a random read buffer is allocated. When you sort a query, # MySQL scans the buffer first to avoid disk searches, improve query speed, and, if you need to sort large amounts of data, raise the value appropriately. However, MySQL will issue this buffer space for each client connection, so you should set this value as appropriately as possible to avoid excessive memory overhead sort_buffer_size=8m# MySQL performs sorting using the buffer size. If you want to increase the speed of the order by, first see if you can let MySQL use the index instead of the extra sort stage. # if not, you can try increasing the size of the sort_buffer_size variable join_buffer_size=8m# The buffer size that can be used by the Federated query operation, as with Sort_buffer_size, the allocated memory for this parameter is also per connection exclusive thread_cache_size=8# This value (default 8) means that the number of threads stored in the cache can be re-used, and if there is room in the cache when disconnected, the client's thread will be placed in the cache, # if the thread is requested again, then the request will be read from the cache, if the cache is empty or a new request, Then this thread will be recreated, if there are many new threads, # Adding this value can improve system performance. You can see the effect of this variable by comparing the variables of the connections and threads_created states. (–>indicates the value to adjust) # According to the physical memory setting rules are as follows: # 1g->8# 2g-> -# 3g-> +# greater than 3g-> -query_cache_size=8m#mysql the query buffer size (from 4.0. 1, MySQL provides a query buffering mechanism) using query buffering, MySQL stores the SELECT statement and query results in a buffer, # future for the same SELECT statement (case sensitive), the result will be read directly from the buffer. Depending on the MySQL user manual, up to 238 can be reached using query buffering%of efficiency. # By checking the status value'qcache_%', you can know whether the query_cache_size setting is reasonable: If the value of Qcache_lowmem_prunes is very large, it indicates that there is often insufficient buffering, # If the value of Qcache_hits is also very large, it indicates that query buffering is used very frequently. You need to increase the buffer size at this point, if the value of qcache_hits is small, it indicates that your query repetition rate is very low, # in this case using query buffering will affect efficiency, you can consider not to query buffering. Additionally, adding Sql_no_cache in the SELECT statement can make it clear that the query buffer is not used Query_cache_limit=2m# Specifies the size of the buffer that a single query can use, and the default 1mkey_buffer_size=4m# Specifies the buffer size to use for the index, increasing the index (for all reads and multiple writes) that can be better processed, to the extent that you can afford it. If you make it too big, the system will start to change pages and really become slow. The parameter can be set to 384M or 512M for a server that has around 4GB. Check the status values key_read_requests and key_reads,# to see if the Key_buffer_size setting is reasonable. Proportional Key_reads/key_read_requests should be as low as possible, # at least 1: -,1: 1000 Better (the above status values can be used with the show status like'key_read%'obtained). Note: This parameter value setting is too large to be the overall efficiency of the server is reduced Ft_min_word_len=4# Lexical Minimum length, default 4transaction_isolation= repeatable-read# MySQL supports 4 types of transaction isolation levels, namely: # READ-uncommitted, read-committed, repeatable-READ, serializable.# if not specified, MySQL defaults to use repeatable-read,oracle the default is read-Committedlog_bin= mysql-Binbinlog_format=mixedexpire_logs_days= -#超过30天的binlog删除log_error=/data/mysql/mysql-Error.log #错误日志路径slow_query_log=1Long_query_time=1#慢查询时间 more than 1 seconds for slow query slow_query_log_file=/data/mysql/mysql-Slow.logperformance_schema=0Explicit_defaults_for_timestamp#lower_case_table_names=1#不区分大小写skip-external-locking #MySQL选项以避免外部锁定. This option turns on default-storage-engine =InnoDB #默认存储引擎innodb_file_per_table=1# InnoDB is a standalone tablespace pattern, and each table in each database generates a data space # Independent tablespace benefits: #1. Each table has a self-contained table space. # 2. The data and indexes for each table will exist in the table space themselves. # 3. You can implement a single table to move through different databases. # 4. The space can be recycled (except for the drop table operation, the empty garbage collector) # Disadvantage: # single table increased too large, such as more than 100g# conclusion: # shared tablespace has few advantages in insert operations. Others do not have a separate table space to perform well. When enabling a stand-alone tablespace, make reasonable adjustments: Innodb_open_filesinnodb_open_files= -# Limit the data of the table that InnoDB can open, if the table in the library is particularly many cases, please add this. This value is 300innodb_buffer_pool_size by default=64m# InnoDB uses a buffer pool to save the index and raw data, unlike myisam.#, the larger you set up, the disk I needed to access the data in the table/o the less. # on a standalone database server, you can set this variable to the size of the server's physical memory%# do not set too large, otherwise, due to the competition of physical memory may cause the operating system to break the page. # Note on 32-bit systems you may be limited to each process2-3. 5G user-level memory limit, # So don't set it too high. Innodb_write_io_threads=4innodb_read_io_threads=4# InnoDB using a background thread to process the read and write I on the data page/O (input and output) request, according to your CPU core number to change, the default is 4# Note: These two parameters do not support dynamic change, you need to add this parameter to the MY.CNF, after modification, restart the MySQL service, allow the range of values from1- -innodb_thread_concurrency=0# The default setting is0, which means that the number of concurrency is not limited, it is recommended to set to 0, better to play CPU multi-core processing capacity, increase concurrency innodb_purge_threads=1# Cleanup in InnoDB is a class of operations that periodically reclaim useless data. In previous releases, the purge operation was part of the main thread, which meant that it could clog other database operations at runtime. # from MySQL5.5. Beginning with the X version, the operation runs on a separate thread and supports more concurrent numbers. The user can set the innodb_purge_threads configuration parameter to select whether the purge operation uses a single #-alone thread, by default the parameter is set to 0 (not using a separate thread), set to1A separate purge thread is used. Recommended for 1innodb_flush_log_at_trx_commit=2# 0: If the value of Innodb_flush_log_at_trx_commit is 0,log buffer, the log file is written to disk every second, and no action is taken when committing the transaction (execution is performed by the MySQL master thread thread.) # Redo log buffers are written to the disk's redo log file (REDO log) every second in the main thread. Whether the transaction has been committed or not, the default log file is ib_logfile0,ib_logfile1#1: When set to the default value of 1, log buffer is written to the log every time a transaction is committed. # 2: If set to 2, each commit transaction will write a log, but will not perform the brush operation. The log file is brushed on a per-second schedule. Note that there is no guarantee that 100%The disk must be brushed every second, depending on the scheduling of the process. # each time a transaction commits, the data is written to the transaction log, where the write is only called the file system's write operation, and the file system is cached, so this write does not guarantee that the data has been written to the physical disk # default value of 1 is to ensure complete acid. Of course, you can set this configuration to a value other than 1 in exchange for higher performance, but you will lose 1 seconds of data when the system crashes. # set to 0, when the mysqld process crashes, it loses the last 1 seconds of the transaction. Set to 2, the last 1 seconds of data will be lost only if the operating system crashes or loses power. InnoDB will ignore this value when doing a recovery. # summary # Set to 1 is certainly the safest, but the performance page is the worst (as opposed to the other two parameters, but not unacceptable). If the data consistency and integrity requirements are not high, can be set to 2, if only the most performance, such as high concurrent write log server, set to zero for higher performance innodb_log_buffer_size=2m# This parameter determines the amount of memory used by the log files, in M. Larger buffers can improve performance, but unexpected failures will cause data loss. MySQL developer recommends setting to 1-8m between Innodb_log_file_size=32m# This parameter determines the size of the data log file, and larger settings can improve performance, but it also increases the time required to recover the failed database Innodb_log_files_in_group=3# To improve performance, MySQL can write log files to multiple files in a circular fashion. Recommended setting to 3innodb_max_dirty_pages_pct= -# InnoDB The main thread flushes the data in the cache pool so that the dirty data scale is less than%Innodb_lock_wait_timeout= -# InnoDB transactions can wait a locked timeout number of seconds before being rolled back. InnoDB automatically detects the transaction deadlock in its own locking table and rolls back the transaction. InnoDB Use the Lock tables statement to notice the locking settings. The default value is 50 seconds bulk_insert_buffer_size=8m# BULK Insert cache size, this parameter is for the MyISAM storage engine. Suitable for insertion in- ++to improve efficiency when recording. The default value is 8M. Can be doubled to the size of the data volume. Myisam_sort_buffer_size=8m# MyISAM Sets the size of the buffer that is used when the table is restored, when the buffer is allocated in repair table or in the CREATE INDEX or ALTER TABLE procedure MyISAM index allocation buffers Myisam_max_sort_file _size=10g# If the temporary file becomes more than the index, do not use the Quick Sort index method to create an index. Note: This parameter is given as a byte myisam_repair_threads=1# If the value is greater than 1, the MyISAM table index (each index in its own line range) is created in parallel during the repair by sorting process interactive_timeout=28800# Number of seconds that the server waits for activity before closing the interactive connection. The interactive client is defined as a client that uses the Client_interactive option in Mysql_real_connect (). Default value: 28,800 seconds (8 hours) Wait_timeout=28800# Number of seconds that the server waits for activity before closing a non-interactive connection. When a thread starts, the session Wait_timeout value is initialized based on the global Wait_timeout value or global interactive_timeout value, # depends on the client type (the connection option by Mysql_real_connect () Client_ Interactive definition). Parameter default value: 28,800 seconds (8 hours) # The maximum number of connections supported by the MySQL server is capped, because each connection is built to consume memory, so we want the client to disconnect and free up memory when connecting to MySQL server after the corresponding operation has been processed. If your MySQL server has a large number of idle connections, they will not only consume memory in vain, but if the connection keeps accumulating, it will eventually reach the MySQL server connection limit, which will be reported'Too many connections'the error. For the value setting of wait_timeout, it should be judged according to the operation condition of the system. # After the system has been running for a period of time, you can see the current system connection status through the show Processlist command, if you find a large number of sleep status of the connection process, then the parameter setting is too large, # can be adjusted to the appropriate smaller. To set Interactive_timeout and wait_timeout at the same time will not take effect. [Mysqldump]quickmax_allowed_packet=16M #服务器发送和接受的最大包长度 [myisamchk]key_buffer_size=8msort_buffer_size=8mread_buffer=4mwrite_buffer= 4M

Reference: http://www.jb51.net/article/48082.htm

MySQL configuration file my.cnf parameter optimization in Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.