MySQL Service performance optimization-my.cnf configuration instructions

Source: Internet
Author: User
Tags one table

MySQL server MY.CNF configuration document detailed
Hardware: Memory 16G

[Client]
Port = 3306
Socket =/data/3306/mysql.sock

[MySQL]
No-auto-rehash

[Mysqld]
user = MySQL
Port = 3306
Socket =/data/3306/mysql.sock
Basedir =/usr/local/mysql
DataDir =/data/3306/data
Open_files_limit = 10240

    at #在MYSQL暂时停止响应新请求之前, the number of requests within a short period of time can be present on the stack. If the system has many connections in a short period of time, you need to increase the value of this parameter, which specifies the size of the listening queue for incoming TCP/IP connections. The default value is 50.
In #MySQL允许最大的进程连接数, if the too many connections error is frequently present, you need to increase this value.
6000 #设置每个主机的连接请求异常中断的最大次数, when this number of times is exceeded, the MySQL server will disallow host connection requests until the MySQL server restarts or clears the host information through the flush hosts command.
614 #指示表调整缓冲区大小. # Table_cache parameter sets the number of table caches. Each connection comes in with at least one table cache open. #因此, the size of the Table_cache should be related to the Max_connections setting. For example, for a 200 # parallel run connection, you should let the table cache have at least 200xN #, where N is the maximum number of tables in a join that the query # can be executed by the application. In addition, some additional file descriptors need to be reserved for temporary tables and files. # when Mysql accesses a table, if the table is already open in the cache, it can access the cache directly, and if # has not been cached, but there are #空间 in the Mysql table buffer, then the table is opened and put into the table slow # flush; If the table cache is full, it will follow certain rules when Unused tables are freed, or temporary widening of the table cache to hold, the advantage of using table caching is that the contents of the table can be accessed more quickly. Execute flush tables # to empty the cached content. In general, you can determine if you need to increase the value of Table_cache by looking at the number #据库运行峰值时间的状态值 open_tables #和 opened_tables (where Open_tables is the number of tables opened before #, O Pened_tables is the number of tables that are already open). That is, if Open_tables is close to Table_cache and #且Opened_tables这个值在逐步增加, consider increasing the size of the # value. There is table_locks_waited higher than the time, also need to increase the table_cache.
external-locking = FALSE #使用 –skip-external-locking mysql option to avoid external locking. This option is turned on by default
Max_allowed_packet = 32M #设置在网络传输中一次消息传输量的最大值. The system defaults to 1MB and the maximum value is 1GB, which must be set to a multiple of 1024.
Sort_buffer_size = 2M # sort_buffer_size is a connection-level parameter that allocates the set of memory once for the first time each connection (session) needs to use this buffer.
#Sort_Buffer_Size is not as large as possible, because it is a connection-level parameter, too large a setting + high concurrency may deplete system memory resources. For example: 500 connections will consume 500*sort_buffer_size (8M) =4g memory
When the #Sort_Buffer_Size exceeds 2KB, memory allocations are made using mmap () rather than malloc (), resulting in reduced efficiency.
Join_buffer_size = 2M #用于表间关联缓存的大小, as with Sort_buffer_size, the allocated memory for this parameter is also exclusive to each connection.
300 # Server Thread cache This value indicates 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, and 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 # and 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. Set the rules as follows: The 1GB memory configuration is 8,2gb configured to 16,3GB configured for 32,4GB or higher memory, which can be configured larger.
8 # Setting the correct value of the thread_concurrency, the performance impact on MySQL, in the case of multiple CPUs (or multicore), the error set the value of Thread_concurrency, will lead to MySQL can not take full advantage of multi-CPU (or multicore), Occurs at the same moment only one CPU (or core) is in the working condition. Thread_co #ncurrency应设为CPU核数的2倍. For example, there is a dual-core CPU, then the thread_concurrency should be 4; 2 Dual-core CPUs, the value of thread_concurrency should be 8
Query_cache_size = 64M # for users who use MySQL, you will not be unfamiliar with this variable. In previous years of MyISAM engine optimization, this parameter was also an important optimization parameter. But with the development, this parameter also reveals some problems. The memory of the machine is getting bigger and larger, and people are accustomed to allocating the previously useful parameters more and more. This #参数加大后也引发了一系列问题. Let's start by analyzing how Query_cache_size works: When a select query works in DB, the DB caches the statement, and when the same SQL comes back to the DB, the DB returns the result from the cache to the client if the table does not change. The #里有一个关建点 is that DB, when working with Query_cache, requires that the table involved in the statement not be changed during this time period. So what happens to the data in Query_cache if the table is changed? The first thing to do is to invalidate the Query_cache and the table-related statements, and then write the update. So #如果Query_cache非常大, the query structure of the table is more, query statement invalidation is slow, an update or insert will be very slow, so see is update or insert how so slow. Therefore, in the database write volume or update volume is also relatively large system, this parameter is not suitable for allocation too large. And in high concurrency, writing #量大的系统, it is recommended to disable this function.
Query_cache_limit = 4M #指定单个查询能够使用的缓冲区大小, default is 1M
Query_cache_min_res_unit = 2k #默认是4KB, setting a large value is good for big data queries, but if your queries are small data queries, it is easy to create memory fragmentation and waste
#查询缓存碎片率 = Qcache_free_blocks/qcache_total_blocks * 100%
#如果查询缓存碎片率超过20%, you can use flush query cache to defragment the cache, or try to reduce query_cache_min_res_unit if your queries are small data volumes.
#查询缓存利用率 = (query_cache_size–qcache_free_memory)/query_cache_size * 100%
#查询缓存利用率在25% below indicates that the Query_cache_size setting is too large, can be appropriately reduced; query cache utilization is above 80% and Qcache_lowmem_prunes > 50 description query_cache_ Size may be a little bit small, or too much fragmentation.
#查询缓存命中率 = (qcache_hits–qcache_inserts)/qcache_hits * 100%
Default-storage-engine = MyISAM #default_table_type = InnoDB
Thread_stack = 192K #设置MYSQL每个线程的堆栈大小, the default value is large enough to satisfy normal operation. Can be set to 128K to 4GB, the default is 192KB
Transaction_isolation = read-committed # # Sets the default transaction isolation level. The available levels are as follows:
# 1.READ uncommitted-READ UNCOMMITTED 2.READ committe-Read Committed 3.REPEATABLE read-repeatable read 4. SERIALIZABLE-Serial
Tmp_table_size = 256M # tmp_table_size The default size is 32M. If a temporary table exceeds that size, MySQL produces an error in the form of the table tbl_name is, and if you do many advanced GROUP by queries, increase the tmp_table_size value. If this value is exceeded, the temporary table is written to disk.
Max_heap_table_size =2 log_long_format log-slow-queries=/data/3306/slow-log.log #log-bin =/data /3306/mysql-bin log-bin binlog_cache_size = 4M max_binlog_cache_size = 8M max_binlog_size =
                
Key_buffer_size = 2048M #批定用于索引的缓冲区大小, increase it to get better index processing performance, for a server with around 4GB, this parameter can be set to 256MB or 384MB.
read_buffer_size = 1M # 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 for a table are frequent, and you think that frequent scans are going too slowly, you can #及内存缓冲区大小提高其性能 by increasing the value of the variable. As with Sort_buffer_size, the allocated memory for this parameter is also exclusive to each connection.
read_rnd_buffer_size = 16M # mysql Random read (query operation) 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, my #Sql会为每个客户连接发放该缓冲空间, so you should set this value as appropriately as possible to avoid excessive memory overhead.
Bulk_insert_buffer_size = 64M #批量插入数据缓存大小, can effectively improve the insertion efficiency, the default is 8M
Myisam_sort_buffer_size = 128M # MyISAM The buffer required for reordering when table is changed
Myisam_max_sort_file_size = 10G # The size of the maximum temporary file allowed when MySQL rebuilds the index (when REPAIR, ALTER TABLE or LOAD DATA INFILE).
# If the file size is larger than this value, the index will be created by the key buffer (slower)
Myisam_max_extra_sort_file_size =
1 # If a table has more than one index, MyISAM can use more than one thread to fix them by using parallel sorting.
# This is a good choice for users with multiple CPUs and a lot of memory.
Myisam_recover #自动检查和修复没有适当关闭的 MyISAM Table
skip-name-1 server-1  
Innodb_additional_mem_pool_size = 16M #这个参数用来设置 The memory pool size of InnoDB stored data directory information and other internal data structures, similar to Oracle's library cache. This is not a mandatory parameter and can be breached.
Innodb_buffer_pool_size = 2048M #这对Innodb表来说非常重要. InnoDB is more sensitive to buffering than the MyISAM table. MyISAM can be run under the default Key_buffer_size settings, but InnoDB is snail-like under the default Innodb_buffer_pool_size settings. Since InnoDB slows down both the data and the index #存起来, there is no need to leave too much memory to the operating system, so you can set it up to 70-80% of usable memory if you only need innodb. Some rules apply to Key_buffer-if you have a small amount of data and do not burst, you do not need to set the Innodb_buffer_pool_size #太大了
Innodb_data_file_path = ibdata1:1024m:autoextend #表空间文件 Important data
4 #文件IO的线程数, typically 4, but under Windows, you can set it larger.
8 #服务器有几个CPU就设置为几, the default setting is recommended, typically 8.
2 # If this parameter is set to 1, the log will be written to disk after each commit transaction. To provide performance, you can set to 0 or 2, but assume the risk of losing data in the event of a failure. A setting of 0 indicates that the transaction log is written to the log file, and the log file is flushed to disk once per second. A setting of 2 indicates that the transaction log will #写入日志 at commit time, but the log file is flushed to disk once each time
Innodb_log_buffer_size = 16M #此参数确定些日志文件所用的内存大小, in M. Larger buffers can improve performance, but unexpected failures will cause data loss. MySQL developer recommends setting the 1-8m between
Innodb_log_file_size = 128M #此参数确定数据日志文件的大小, in M, larger settings can improve performance, but also increase the time required to recover the failed database
3 #为提高性能, MySQL can write log files to multiple files in a circular manner. Recommended set to 3M
#推荐阅读 http://www.taobaodba.com/html/221_innodb_max_dirty_pages_pct_checkpoint.html
# The amount of dirty_page in Buffer_pool directly affects the closing time of the InnoDB.                     The parameter innodb_max_dirty_pages_pct can directly control the ratio of dirty_page in Buffer_pool, and fortunately innodb_max_dirty_pages_pct can be dynamically changed. #。 Therefore, the innodb_max_dirty_pages_pct is reduced before closing the InnoDB, forcing the data block to flush for a period of time, which can greatly shorten the time of MySQL shutdown.
# InnoDB has its built-in deadlock detection mechanism that can cause incomplete transactions to be rolled back. However, if you combine InnoDB with a MYISAM lock tables statement or a third-party transaction engine, the INNODB does not recognize the deadlock. To eliminate this possibility, you can set Innodb_lock_wait_timeout to an integer value #, which indicates how long (in seconds) the MySQL waits before allowing other transactions to modify data that is eventually rolled back by the transaction
0 #独享表空间 (OFF)
[Mysqldump] Quick Max_allowed_packet = 32M [mysqld_safe] log-error=/data/3306/mysql_oldboy.err pid-  file=/data/3306/mysqld.pid    
  #指定一个请求的最大连接时间, you can set it to 5 for a memory server around 4GB. #skip_networking  #开启该选可以彻底关闭MYSQL的TCP/IP connection, do not turn on this option if the Web server is accessing the MySQL database server remotely, otherwise it will not connect properly. #log-queries-not-using-Indexes A query that does not use an index is also recorded    

MySQL Service performance optimization-my.cnf configuration instructions

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.