Go MySQL Performance tuning my.cnf detailed

Source: Internet
Author: User
Tags bulk insert create index

MySQL Performance tuning my.cnf detailed


Provides a MySQL 5.6 version suitable for MY.CNF profiles on 1GB memory VPS (click here to download the file):

  1. [Client]
  2. Port = 3306
  3. Socket =/tmp/mysql.sock
  4. [Mysqld]
  5. Port = 3306
  6. Socket =/tmp/mysql.sock
  7. Basedir =/usr/local/mysql
  8. DataDir =/data/mysql
  9. Pid-file =/data/mysql/mysql.pid
  10. user = MySQL
  11. bind-address =
  12. Server-id = 1 #表示是本机的序号为1, which is generally the meaning of master
  13. Skip-name-resolve
  14. # Disable MySQL for DNS resolution of external connections and use this option to eliminate the time for DNS resolution for MySQL. But be aware that if you turn on this option,
  15. # All remote host connections are authorized to use IP address, otherwise MySQL will not be able to handle connection requests properly
  16. #skip-networking
  17. Back_log =
  18. # Number of connections MySQL can have. This works when the primary MySQL thread gets very many connection requests in a very short period of time,
  19. # 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.
  20. # If you expect to have a lot of connections in a short period of time, you need to add it. That is, if MySQL's connection data reaches Max_connections, the new request will be present in the stack,
  21. # to wait for a connection to release resources, the number of the stack is Back_log, and if the number of waiting connections exceeds back_log, the connection resource will not be granted.
  22. In addition, this value (Back_log) is limited to the size of your operating system's listening queue for incoming TCP/IP connections.
  23. # 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.
  24. Max_connections = +
  25. # 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. The ' conn% ' wildcard character can be used to view the number of connections in the current state to decide the size of the value.
  26. Max_connect_errors = 6000
  27. # 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.
  28. Open_files_limit = 65535
  29. # MySQL Open file descriptor limit, default minimum 1024, when Open_files_limit is not configured, compare the values of max_connections*5 and ulimit-n, which big use which,
  30. # when OPEN_FILE_LIMIT is configured, compare the values of open_files_limit and max_connections*5, whichever is larger.
  31. Table_open_cache =
  32. # 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. Default Value 64
  33. # Assuming the system has 200 concurrent connections, you need to set this parameter to 200*n (N is the number of file descriptors required for each connection);
  34. # when the Table_open_cache is set to very large, if the system can not handle so many file descriptors, then the client will fail, the connection is not
  35. Max_allowed_packet = 4M
  36. # The size of the packet accepted; It is safe to increase the value of the 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.
  37. # 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.
  38. Binlog_cache_size = 1M
  39. # A transaction that, when not committed, logs the log to the cache, and persists the log to disk until the commit of the transaction is required. Default Binlog_cache_size size 32K
  40. Max_heap_table_size = 8M
  41. # defines the size of memory table that the user can create. This value is used to calculate the maximum row value for the memory table. This variable supports dynamic change
  42. Tmp_table_size = 16M
  43. # MySQL heap (heap) table buffer size. All unions are completed within a DML instruction, and most unions can be done without a temporary table.
  44. # 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.
  45. # 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 the value is raised, MySQL will increase the size of the heap, which can improve the speed of the join query.
  46. Read_buffer_size = 2M
  47. # MySQL read into 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.
  48. # 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
  49. Read_rnd_buffer_size = 8M
  50. # mysql 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,
  51. # MySQL will first scan the buffer to avoid disk search, improve query speed, and if you need to sort large amounts of data, you can adjust the value appropriately. However, MySQL will issue this buffer space for each client connection, so you should set this value as appropriate to avoid excessive memory overhead
  52. Sort_buffer_size = 8M
  53. # 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.
  54. # If you can't, try increasing the size of the sort_buffer_size variable
  55. Join_buffer_size = 8M
  56. # The buffer size that can be used by the union query operation, as with Sort_buffer_size, the allocated memory for this parameter is also per connection exclusive
  57. Thread_cache_size = 8
  58. # 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.
  59. # 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 the thread will be recreated, if there are many new threads,
  60. # Increasing 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)
  61. # According to the physical memory setting rules are as follows:
  62. # 1g-> 8
  63. # 2g->
  64. # 3g->
  65. # greater than 3g->
  66. Query_cache_size = 8M
  67. #MySQL的查询缓冲大小 (starting with 4.0.1, MySQL provides a query buffering mechanism) using query buffering, MySQL stores the SELECT statement and query results in a buffer,
  68. # Future for the same SELECT statement (case sensitive), the result will be read directly from the buffer. Depending on the MySQL user manual, the use of query buffering can be up to 238% efficient.
  69. # 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,
  70. # If the value of the qcache_hits is also very large, it indicates that the query buffer is used very frequently, the buffer size needs to be increased, and if the value of qcache_hits is small, your query repetition rate is very low.
  71. # In this case, the use of query buffering can affect efficiency, so consider not querying the buffers. Additionally, adding Sql_no_cache in the SELECT statement can make it clear that the query buffer is not used
  72. Query_cache_limit = 2M
  73. #指定单个查询能够使用的缓冲区大小, default 1M
  74. Key_buffer_size = 4M
  75. #指定用于索引的缓冲区大小, increase it to get better processing index (for all read and multiple writes), to the extent that you can afford it. If you make it too big,
  76. # The system will start changing pages and really slows down. The parameter can be set to 384M or 512M for a server that has around 4GB. By checking the status values key_read_requests and Key_reads,
  77. # you can tell if the key_buffer_size settings are reasonable. The proportional key_reads/key_read_requests should be as low as possible,
  78. # At least 1:100,1:1000 is better (the above status values can be obtained using show status like ' key_read% '). Note: This parameter value setting is too large to be the overall efficiency of the server is reduced
  79. Ft_min_word_len = 4
  80. # lexical Minimum length, default 4
  81. Transaction_isolation = Repeatable-read
  82. # MySQL supports 4 types of transaction isolation levels, namely:
  83. # read-uncommitted, read-committed, Repeatable-read, SERIALIZABLE.
  84. # if not specified, MySQL defaults to repeatable-read,oracle default is read-committed
  85. Log_bin = Mysql-bin
  86. Binlog_format = Mixed
  87. Expire_logs_days = #超过30天的binlog删除
  88. Log_error =/data/mysql/mysql-error.log #错误日志路径
  89. Slow_query_log = 1
  90. Long_query_time = 1 #慢查询时间 more than 1 seconds for slow query
  91. Slow_query_log_file =/data/mysql/mysql-slow.log
  92. Performance_schema = 0
  93. Explicit_defaults_for_timestamp
  94. #lower_case_table_names = 1 #不区分大小写
  95. Skip-external-locking #MySQL选项以避免外部锁定. This option is turned on by default
  96. Default-storage-engine = InnoDB #默认存储引擎
  97. innodb_file_per_table = 1
  98. # InnoDB is a standalone tablespace pattern, and each table in each database generates a data space
  99. # Standalone Table Space benefits:
  100. # 1. Each table has a self-contained table space.
  101. # 2. The data and indexes for each table will exist in the table space themselves.
  102. # 3. You can implement a single table to move through different databases.
  103. # 4. Space can be recycled (except for the drop table operation, the meter is not able to recycle)
  104. Disadvantages
  105. # single table increased too large, such as more than 100G
  106. Conclusion
  107. # shared tablespace has few advantages over insert operations. Others do not have a separate table space to perform well. When enabling a stand-alone tablespace, make reasonable adjustments: Innodb_open_files
  108. Innodb_open_files =
  109. # 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 300 by default.
  110. Innodb_buffer_pool_size = 64M
  111. # InnoDB uses a buffer pool to hold indexes and raw data, unlike MyISAM.
  112. # The larger you set up, the less disk I/O you need to access the data in the table.
  113. # on a standalone database server, you can set this variable to 80% of the server's physical memory size
  114. # do not set too large, otherwise, due to the competition of physical memory may cause the operating system to break the page.
  115. # Note on 32-bit systems you each process may be limited to 2-3.5g user-level memory limits,
  116. # so don't set it too high.
  117. Innodb_write_io_threads = 4
  118. Innodb_read_io_threads = 4
  119. # InnoDB uses a background thread to process read/write I/O (input and output) requests on the data page, changing according to the number of CPU cores, default is 4
  120. # Note: These two parameters do not support dynamic changes, you need to add this parameter to the MY.CNF, after modification, restart the MySQL service, the allowable value range from 1-64
  121. Innodb_thread_concurrency = 0
  122. # The default setting is 0, which means no limit on concurrency, the recommended setting is 0, better to play CPU multicore processing capacity, increase concurrency
  123. Innodb_purge_threads = 1
  124. # 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.
  125. # Starting with the mysql5.5.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
  126. # single-threaded, by default the parameter is set to 0 (not using a separate thread), when set to 1 means a separate purge thread is used. Recommended for 1
  127. Innodb_flush_log_at_trx_commit = 2
  128. # 0: If the value of Innodb_flush_log_at_trx_commit is 0,log buffer, the log file will be written to disk every second, and no action is taken when committing the transaction (execution is performed by the MySQL master thread thread.)
  129. # 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
  130. # 1: When set to the default value of 1, log buffer will be written to the log every time the transaction is committed.
  131. # 2: If set to 2, each commit transaction will write the 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% per second will be brushed to disk, depending on the scheduling of the process.
  132. # each time a transaction commits, the data is written to the transaction log, where the write is only called the file system, and the filesystem is cached, so this write does not guarantee that the data has been written to the physical disk
  133. # The 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.
  134. # 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.
  135. # Summary
  136. # 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 for performance, such as high concurrent write log server, set to zero for higher performance
  137. Innodb_log_buffer_size = 2M
  138. # 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 the 1-8m between
  139. Innodb_log_file_size = 32M
  140. # This parameter determines the size of the data log file, larger settings can improve performance, but also increases the time required to recover the failed database
  141. Innodb_log_files_in_group = 3
  142. # to improve performance, MySQL can write log files to multiple files in a circular fashion. Recommended setting is 3
  143. innodb_max_dirty_pages_pct =
  144. # InnoDB The main thread flushes the data in the cache pool so that the dirty data scale is less than 90%
  145. Innodb_lock_wait_timeout =
  146. # 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
  147. Bulk_insert_buffer_size = 8M
  148. # BULK INSERT cache size, this parameter is for the MyISAM storage engine. For increased efficiency when inserting 100-1000+ records at once. The default value is 8M. Can be doubled to the size of the data volume.
  149. Myisam_sort_buffer_size = 8M
  150. # MyISAM Sets the size of the buffer to be used when restoring the table, when the buffer is allocated in repair table or in the order of the MyISAM index when the index is created or the ALTER TABLE is indexed with CREATE index
  151. Myisam_max_sort_file_size = 10G
  152. # 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
  153. Myisam_repair_threads = 1
  154. # If the value is greater than 1, the MyISAM table index (each index in its own line range) is created in parallel in the repair by sorting procedure
  155. Interactive_timeout = 28800
  156. # 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)
  157. Wait_timeout = 28800
  158. # Number of seconds that the server waits for activity before closing a non-interactive connection. Initializes the session Wait_timeout value based on the global Wait_timeout value or global interactive_timeout value when the thread starts,
  159. # depends on the client type (defined by the connection option Client_interactive Mysql_real_connect ()). Parameter default value: 28,800 seconds (8 hours)
  160. # 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 be connected to MySQL server after the corresponding operation is processed,
  161. # You should disconnect and release the memory that is occupied. If your MySQL server has a lot of idle connections, they will not only consume memory in vain, but if the connection keeps accumulating,
  162. # Eventually the number of connections to MySQL server will be reached, which will be reported as ' too many connections ' error. For the value setting of wait_timeout, it should be judged according to the operation condition of the system.
  163. # After the system has been running for a period of time, you can view the current system's connection status through the show Processlist command, if you find a large number of sleep status of the connection process, the parameter setting is too large,
  164. # you can make the appropriate adjustments smaller. To set Interactive_timeout and wait_timeout at the same time will not take effect.
  165. [Mysqldump]
  166. Quick
  167. Max_allowed_packet = 16M #服务器发送和接受的最大包长度
  168. [Myisamchk]
  169. Key_buffer_size = 8M
  170. Sort_buffer_size = 8M
  171. Read_buffer = 4M
  172. Write_buffer = 4M

Go MySQL Performance tuning my.cnf detailed

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.