MySQL Performance tuning my.cnf detailed
Https://blog.linuxeye.cn/379.html
Provides a MySQL 5.6 version suitable for MY.CNF profiles on 1GB memory VPS (click here to download the file):
- [Client]
- Port = 3306
- Socket =/tmp/mysql.sock
- [Mysqld]
- Port = 3306
- Socket =/tmp/mysql.sock
- Basedir =/usr/local/mysql
- DataDir =/data/mysql
- Pid-file =/data/mysql/mysql.pid
- user = MySQL
- bind-address = 0.0.0.0
- Server-id = 1 #表示是本机的序号为1, which is generally the meaning of master
- Skip-name-resolve
- # 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,
- # All remote host connections are authorized to use IP address, otherwise MySQL will not be able to handle connection requests properly
- #skip-networking
- Back_log =
- # 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,
- # 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 MySQL's connection data reaches Max_connections, the new request will be present in the stack,
- # 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.
- In addition, this value (Back_log) is limited to the size of your operating system's listening queue for incoming TCP/IP connections.
- # 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. The ' conn% ' wildcard character can be used to 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 the values of max_connections*5 and ulimit-n, which big use which,
- # when OPEN_FILE_LIMIT is configured, compare the values of open_files_limit and max_connections*5, whichever is larger.
- 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. Default Value 64
- # 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);
- # 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
- Max_allowed_packet = 4M
- # 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.
- # 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 log to the cache, and persists the log to disk until the commit of the transaction is required. Default Binlog_cache_size size 32K
- Max_heap_table_size = 8M
- # 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
- 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 the value is raised, MySQL will increase the size of the heap, which can improve the speed of the join query.
- Read_buffer_size = 2M
- # 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.
- # 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 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 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
- 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 you can't, try increasing the size of the sort_buffer_size variable
- Join_buffer_size = 8M
- # 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
- 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 the thread will be recreated, if there are many new threads,
- # 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)
- # According to the physical memory setting rules are as follows:
- # 1g-> 8
- # 2g->
- # 3g->
- # greater than 3g->
- Query_cache_size = 8M
- #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,
- # 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.
- # 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 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.
- # 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
- Query_cache_limit = 2M
- #指定单个查询能够使用的缓冲区大小, default 1M
- Key_buffer_size = 4M
- #指定用于索引的缓冲区大小, 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,
- # 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,
- # you can tell if the key_buffer_size settings are reasonable. The proportional key_reads/key_read_requests should be as low as possible,
- # 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
- Ft_min_word_len = 4
- # lexical Minimum length, default 4
- Transaction_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 repeatable-read,oracle default is read-committed
- Log_bin = Mysql-bin
- Binlog_format = Mixed
- Expire_logs_days = #超过30天的binlog删除
- Log_error =/data/mysql/mysql-error.log #错误日志路径
- Slow_query_log = 1
- Long_query_time = 1 #慢查询时间 more than 1 seconds for slow query
- Slow_query_log_file =/data/mysql/mysql-slow.log
- Performance_schema = 0
- Explicit_defaults_for_timestamp
- #lower_case_table_names = 1 #不区分大小写
- Skip-external-locking #MySQL选项以避免外部锁定. This option is turned on by default
- 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
- # Standalone Table Space 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. Space can be recycled (except for the drop table operation, the meter is not able to recycle)
- Disadvantages
- # single table increased too large, such as more than 100G
- Conclusion
- # 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
- Innodb_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 300 by default.
- Innodb_buffer_pool_size = 64M
- # InnoDB uses a buffer pool to hold indexes and raw data, unlike MyISAM.
- # The larger you set up, the less disk I/O you need to access the data in the table.
- # on a standalone database server, you can set this variable to 80% of the server's physical memory size
- # 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 each process may be limited to 2-3.5g user-level memory limits,
- # so don't set it too high.
- Innodb_write_io_threads = 4
- Innodb_read_io_threads = 4
- # 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
- # 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
- Innodb_thread_concurrency = 0
- # 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
- 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.
- # 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
- # 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
- Innodb_flush_log_at_trx_commit = 2
- # 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.)
- # 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 will be written to the log every time the transaction is committed.
- # 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.
- # 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
- # 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.
- # 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 for 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 the 1-8m between
- Innodb_log_file_size = 32M
- # 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
- Innodb_log_files_in_group = 3
- # to improve performance, MySQL can write log files to multiple files in a circular fashion. Recommended setting is 3
- innodb_max_dirty_pages_pct =
- # InnoDB The main thread flushes the data in the cache pool so that the dirty data scale is less than 90%
- 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. 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.
- Myisam_sort_buffer_size = 8M
- # 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
- 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 in the repair by sorting procedure
- 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. Initializes the session Wait_timeout value based on the global Wait_timeout value or global interactive_timeout value when the thread starts,
- # depends on the client type (defined by the connection option Client_interactive Mysql_real_connect ()). 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 be connected to MySQL server after the corresponding operation is processed,
- # 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,
- # 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.
- # 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,
- # you can make the appropriate adjustments smaller. To set Interactive_timeout and wait_timeout at the same time will not take effect.
- [Mysqldump]
- Quick
- Max_allowed_packet = 16M #服务器发送和接受的最大包长度
- [Myisamchk]
- Key_buffer_size = 8M
- Sort_buffer_size = 8M
- Read_buffer = 4M
- Write_buffer = 4M
Go MySQL Performance tuning my.cnf detailed