[Turn] Detailed explanation of Mysql configuration 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 # indicates that the serial number of this machine is 1 , generally speaking, it means master

skip-name-resolve
# Disables MySQL's DNS resolution for external connections. Using this option can eliminate MySQL's DNS resolution time. However, it should be noted that if this option is enabled,
# All remote host connection authorizations must use the IP address method, otherwise MySQL will not be able to process connection requests normally

#skip-networking

back_log = 600
# The number of connections that MySQL can have. This works when the main MySQL thread gets a lot of connection requests in a short period of time,
# then the main thread takes some time (albeit a short time) to check for connections and starts a new thread. The back_log value indicates how many requests can be stored on the stack for a short period of time before MySQL temporarily stops answering new requests.
# You need to increase this if you expect many connections in a short period of time. That is to say, if the connection data of MySQL reaches max_connections, the new request will be stored in the stack,
# To wait for a connection to release resources, the number of the stack is back_log, if the number of waiting connections exceeds the back_log, it will not be been granted connection resources.
# Also, this value (back_log) is limited to the size of your OS's listen queue for incoming TCP/IP connections.
# Your OS has its own limit on this queue size (check your OS documentation for the maximum value of this variable), trying to set back_log higher than your OS's limit will be ineffective.

max_connections = 1000
# The maximum number of connections for MySQL. If the number of concurrent connection requests on the server is relatively large, it is recommended to increase this value to increase the number of parallel connections. Of course, this is based on the machine can support it, because if the number of connections increases, Since MySQL will provide a connection buffer for each connection, it will cost more memory, so adjust the value appropriately, and cannot blindly increase the value. You can use the 'conn%' wildcard to view the number of connections in the current state to determine the size of this value.

max_connect_errors = 6000
# For the same host, if there are more than the number of interrupted error connections in this parameter, the host will be prohibited from connecting. To unblock the host, execute: FLUSH HOST.

open_files_limit = 65535
# The limit of file descriptors opened by MySQL, the default minimum is 1024; when open_files_limit is not configured, compare the values ​​of max_connections*5 and ulimit -n, whichever is larger,
# When open_file_limit is configured, compare open_files_limit And the value of max_connections*5, whichever is larger is used.

table_open_cache = 128
# Every time MySQL opens a table, it will read some data into the table_open_cache cache. When MySQL cannot find the corresponding information in this cache, it will read it from the disk. The default value is 64
# Assuming that 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 table_open_cache is set to a large value, if the system processes If there are not so many file descriptors, then the client will fail and the connection will not be possible.

max_allowed_packet = 4M
# Accepted packet size; increasing the value of this variable is safe because additional memory is allocated only when needed. For example, MySQLd allocates more memory only when you issue long queries or MySQLd must return large result rows.
# The small default value of this variable is a precautionary measure to catch bad packets between client and server, and to ensure that memory overflow is not caused by accidental use of large packets.

binlog_cache_size = 1M
# For a transaction, when it is not committed, the log generated is recorded in the Cache; when the transaction is committed and needs to be committed, the log is persisted to disk. The default binlog_cache_size size is 32K

max_heap_table_size = 8M
# Defines the size of the memory table that the user can create. This value is used to calculate the maximum row value of the memory table. This variable supports dynamic changes

tmp_table_size = 16M
# MySQL heap table buffer size. All joins are done within one DML instruction, and most joins can even be done without temporary tables.
# Most temporary tables are memory-based (HEAP) tables. Temporary tables with large record lengths (the sum of the lengths of all columns) or tables containing BLOB columns are stored on disk.
# If the size of an internal heap table exceeds tmp_table_size, MySQL can automatically change the in-memory heap table to a hard disk-based MyISAM table as needed. It is also possible to increase the size of temporary tables by setting the tmp_table_size option. That is to say, if you increase the value, MySQL will increase the size of the heap table at the same time, which can achieve the effect of improving the speed of join query.

read_buffer_size = 2M
# MySQL read buffer size. A request for a sequential scan of a table will allocate a read buffer, and MySQL will allocate a memory buffer for it. The read_buffer_size variable controls the size of this buffer.
# If the sequential scan request to the table is very frequent, and you think the frequent scan is too slow, you can improve its performance by increasing the value of this 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 sorted order), a random read buffer is allocated. When performing a sorting query,
# MySQL will first scan the buffer to avoid disk search and improve query speed. If you need to sort a large amount of data, you can increase the value appropriately. However, MySQL will allocate this buffer space for each client connection, so you should try to set this value appropriately to avoid excessive memory overhead

sort_buffer_size = 8M
# The buffer size used by MySQL to perform sorting. If you want to increase the speed of ORDER BY, first see if you can get MySQL to use an index instead of an extra sort stage.
# If not, try increasing the size of the sort_buffer_size variable

join_buffer_size = 8M
# The size of the buffer that can be used by the joint query operation. Like sort_buffer_size, the allocated memory corresponding to this parameter is also exclusive to each connection

thread_cache_size = 8
# This value (default 8) indicates the number of threads that can be reused in the cache. If there is space in the cache when disconnecting, the client's thread will be placed in the cache.
# If the thread is re-used request, 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. By comparing Connections And the variable of the Threads_created state, you can see the role of this variable. (–> indicates the value to be adjusted)
# According to the physical memory setting rules are as follows:
# 1G —> 8
# 2G —> 16
# 3G —> 32
# Greater than 3G —> 64

query_cache_size = 8M
#MySQL's query buffer size (starting from 4.0.1, MySQL provides a query buffering mechanism) using query buffering, MySQL stores SELECT statements and query results in the buffer,
# In the future, for the same SELECT statement (size-sensitive write), the result will be read directly from the buffer. According to the MySQL user manual, using query buffering can achieve up to 238% 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 the buffer is often insufficient,
# If the value of Qcache_hits is also very large, it indicates that the query buffer is used very frequently, At this time, you need to increase the buffer size; if the value of Qcache_hits is not large, it means that your query repetition rate is very low.
# In this case, using query buffering will affect the efficiency, so you can consider not using query buffering. In addition, adding SQL_NO_CACHE to the SELECT statement makes it clear that query buffering is not used

query_cache_limit = 2M #Specify
the buffer size that a single query can use, the default is 1M

key_buffer_size = 4M #Specify
the buffer size used for indexing, increase it to get better handled indexing (for all reads and multiple rewrites), as much as you can afford. If you make it too big,
# the system will start wrapping and get really slow. For servers with about 4GB of memory, this parameter can be set to 384M or 512M. By checking the status values ​​Key_read_requests and Key_reads,
# you can know whether the key_buffer_size setting is reasonable. The ratio 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: If this parameter value is set too large, it will reduce the overall efficiency of the server.

ft_min_word_len = 4
# Minimum length of word segmentation vocabulary, default 4

transaction_isolation = REPEATABLE-READ
# MySQL supports 4 transaction isolation levels, they are:
# READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE.
# If not specified, MySQL uses REPEATABLE-READ by default, ORACLE default is READ-COMMITTED

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30 #delete binlog over 30 days

log_error = /data/mysql/mysql-error.log #Error log path
slow_query_log = 1
long_query_time = 1 #If the slow query time exceeds 1 second, it is a slow query
slow_query_log_file = /data/mysql/mysql-slow.log

performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1 #Case insensitive

skip-external-locking #MySQL option to avoid external locking. This option is enabled by default

default-storage-engine=InnoDB #default storage engine

innodb_file_per_table = 1
# InnoDB is an independent table space mode, each table in each database will generate a data space
# Independent table space advantages:
# 1. Each table has its own independent tablespace.
# 2. The data and indexes of each table will exist in its own tablespace.
# 3. A single table can be moved in different databases.
# 4. Space can be reclaimed (except for drop table operations, table space cannot be reclaimed by itself)
# Disadvantages:
# The increase of a single table is too large, such as more than 100G
# Conclusion:
# Shared table space has few advantages in Insert operation. Others do not perform well in independent tablespaces. When enabling independent tablespaces, please adjust appropriately: innodb_open_files

innodb_open_files = 500
# Limit the data of tables that Innodb can open. If there are too many tables in the library, please increase this. This value defaults to 300

innodb_buffer_pool_size = 64M
# InnoDB uses a buffer pool to store indexes and raw data, unlike MyISAM.
# The larger you set here, the less disk I/O you need to access data in the table.
# In a standalone use On the database server of 2020, you can set this variable to 80% of the server's physical memory size
# Do not set it too large, otherwise, the operating system may cause page thrashing due to physical memory contention.
# Note that on 32-bit systems you each Processes may be limited to the 2-3.5G user-level memory limit,
# so don't set it too high.

innodb_write_io_threads = 4
innodb_read_io_threads = 4
# innodb uses background threads to process read and write I/O (input and output) requests on data pages, which can be changed according to the number of CPU cores you have, the default is 4
# Note: These two parameters do not support dynamic changes , you need to add this parameter to my.cnf, restart the MySQL service after modification, the allowable value range is from 1-64

innodb_thread_concurrency = 0
# The default setting is 0, which means that there is no limit to the number of concurrency. It is recommended to set it to 0 here to better utilize the multi-core processing capability of the CPU and increase the amount of concurrency

innodb_purge_threads = 1
# The purge operation in InnoDB is a type of operation that periodically recycles useless data. In previous versions, the cleanup operation was part of the main thread, which meant that it might block other database operations at runtime.
# Starting from MySQL 5.5.X, this operation runs in a separate thread and supports more concurrency. The user can choose whether to use a single
thread for the purge operation by setting the innodb_purge_threads configuration parameter. By default, the parameter is set to 0 (do not use a separate thread), and when it is set to 1, it means that a separate purge thread is used. 1 is recommended

innodb_flush_log_at_trx_commit = 2
# 0: If the value of innodb_flush_log_at_trx_commit is 0, the log buffer will be flushed to the disk every second, and no operation will be done when the transaction is committed (execution is performed by the master thread of mysql.
# Main The thread will write the redo log buffer to the redo log file (REDO LOG) on the disk every second. 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, Every time a transaction is committed, the log buffer is flushed to the log.
# 2: If set to 2, the log will be written every time a transaction is committed, but the brush operation will not be performed. The log file is periodically flushed every second. It should be noted that there is no guarantee that 100% will be flushed to disk every second, which depends on the scheduling of the process.
# Write data to the transaction log every time a transaction is committed, and the write here is only to call the write operation of the file system, and the file system has a cache, so this write does not guarantee that the data has been written to the Physical Disk
# The default value of 1 is to ensure full ACID. Of course, you can set this configuration item to a value other than 1 in exchange for higher performance, but when the system crashes, you will lose 1 second of data.
# If set to 0, when the mysqld process crashes, the last 1 second of transactions will be lost. Set to 2, the last 1 second of data will be lost only when the operating system crashes or loses power. InnoDB ignores this value when doing recovery.
# Summary
# Set to 1 is of course the safest, but the performance page is the worst (relative to the other two parameters, but not unacceptable). If the requirements for data consistency and integrity are not high, it can be set to 2. If only the most performance is required, such as a log server with high concurrent writing, set it to 0 to obtain higher performance.

innodb_log_buffer_size = 2M
# This parameter determines the memory size used by these log files, in M ​​units. Larger buffers can improve performance, but unexpected failures will lose data. MySQL developers recommend setting between 1-8M

innodb_log_file_size = 32M
# This parameter determines the size of the data log file, larger settings can improve performance, but also increase the time required to recover a failed database

innodb_log_files_in_group = 3
# To improve performance, MySQL can write log files to multiple files in a round-robin fashion. Recommended setting is 3

innodb_max_dirty_pages_pct = 90
# The innodb main thread refreshes the data in the buffer pool, so that the proportion of dirty data is less than 90%

innodb_lock_wait_timeout = 120
# The timeout in seconds that an InnoDB transaction can wait for a lock before being rolled back. InnoDB automatically detects transaction deadlocks and rolls back transactions in its own locking tables. InnoDB notices lock settings with the LOCK TABLES statement. The default value is 50 seconds

bulk_insert_buffer_size = 8M
# Bulk insert buffer size, this parameter is for the MyISAM storage engine. It is suitable for improving efficiency when inserting 100-1000+ records at one time. The default value is 8M. It can be doubled according to the size of the data volume.

myisam_sort_buffer_size = 8M
# MyISAM sets the size of the buffer used when restoring the table, when sorting the buffer allocated by the MyISAM index during REPAIR TABLE or CREATE INDEX to create an index or ALTER TABLE

myisam_max_sort_file_size = 10G
# Do not use the quicksort index method to create an index if the temp file will grow to exceed the index. Note: This parameter is given in bytes

myisam_repair_threads = 1
# If the value is greater than 1, MyISAM table indexes are created in parallel during the Repair by sorting process (each index is in its own thread) 

interactive_timeout = 28800
# The number of seconds the server waits for activity before closing an interactive connection. Interactive clients are defined as clients that use the CLIENT_INTERACTIVE option in mysql_real_connect(). Default: 28800 seconds (8 hours)

wait_timeout = 28800
# The number of seconds the server waits for activity before closing a non-interactive connection. At thread startup, the session wait_timeout value is initialized according to the global wait_timeout value or the global interactive_timeout value,
# depending on the client type (defined by the connection option CLIENT_INTERACTIVE of mysql_real_connect()). Parameter default value: 28800 seconds (8 hours)
# There is an upper limit on the maximum number of connections supported by the MySQL server, because the establishment of each connection will consume memory, so we hope that the client will connect to the MySQL Server and process the corresponding operation after the corresponding operation. ,
# should disconnect and free the occupied memory. If your MySQL Server has a large number of idle connections, they will not only consume memory in vain, but if the connections keep accumulating and not disconnecting,
# will eventually reach the upper limit of MySQL Server connections, which will report a 'too many connections' error . For the value setting of wait_timeout, it should be judged according to the operation of the system.
# After the system has been running for a period of time, you can use the show processlist command to view the connection status of the current system. If a large number of connection processes in the sleep state are found, the parameter setting is too large.
# It can be adjusted appropriately. To set both interactive_timeout and wait_timeout will take effect.

[mysqldump]
quick
max_allowed_packet = 16M #Maximum packet length sent and received by the server

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

 

(two)

[mysqld]
port = 3306
serverid = 1
socket = /tmp/mysql.sock
skip-name-resolve #Prohibit
MySQL from performing DNS resolution on external connections. Using this option can eliminate the time for MySQL to perform DNS resolution. However, it should be noted that if this option is enabled, all remote host connection authorizations must use the IP address method, otherwise MySQL will not be able to process connection requests normally! Note: If you use winform to connect to mysql, adding this sentence will greatly improve the speed

skip-locking
# Avoid MySQL's external locking, reduce the chance of errors and enhance stability.

back_log=384
specifies the number of possible connections to MySQL. When the MySQL main thread receives a very large number of connection requests in a short period of time, this parameter takes effect. The main thread spends a short time to check the connection and start a new thread. The value of the back_log parameter indicates how many requests can be stored on the stack for a short period of time before MySQL temporarily stops responding to new requests. 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. Different operating systems have their own limits on this queue size. Attempting to set back_log higher than your operating system's limit will be ineffective. The default value is 50. For Linux systems, it is recommended to set it to an integer less than 512.

key_buffer_size = 32M
# key_buffer_size This is very important for MyISAM tables. If only using MyISAM tables, you can set it to 30-40% of available memory. Reasonable values ​​depend on index size, data volume, and load - keep in mind that MyISAM tables use the operating system's cache to cache data, so some memory needs to be set aside for them, and in many cases the data is larger than the index. Nonetheless, always check that all key_buffers are used - it is very rare that a .MYI file is only 1GB and the key_buffer is set to 4GB. It's such a waste. If you rarely use MyISAM tables, also keep key_buffer_size below 16-32MB to accommodate temporary table indexes given to disk.

innodb_buffer_pool_size = 2.4G
#This is very important for Innodb tables. Innodb is more sensitive to buffering than MyISAM tables. MyISAM works fine with the default key_buffer_size setting, but Innodb is snail-like with the default innodb_buffer_pool_size setting. Since Innodb caches data and indexes, there is no need to leave too much memory for the operating system, so if you only need to use Innodb, you can set it up to 70-80% of the available memory. - If your data volume is not large and will not explode, then you don't need to set innodb_buffer_pool_size too large.

innodb_additional_pool_size = 20M #This
option doesn't have much impact on performance, at least on operating systems with almost enough memory to allocate. But if you still want to set it to 20MB (or more), so you need to look at how much other memory Innodb needs to allocate.

innodb_log_file_size = 512M #Important
in case of high write load especially with large datasets. The higher the value, the higher the performance, but be aware that the recovery time may be increased. I often set it to 64-512MB, depending on server size.

innodb_log_buffer_size = 16M #The
default setting allows server performance to be ok under medium-intensity write loads and short transactions. If there is a peak update operation or if the load is heavy, you should consider increasing its value. If its value is set too high, it may waste memory - it refreshes every second, so there is no need to set more than 1 second of required memory space. Usually 8-16MB is enough. The smaller the system, the smaller its value.

innodb_flush_logs_at_trx_commit = 2
#Is it because Innodb is 1000 times slower than MyISAM and the head is big? It seems that maybe you forgot to modify this parameter. The default value is 1, which means that every committed update transaction (or every statement outside of a transaction) is flushed to disk, which is quite resource-intensive, especially without a battery-backed cache. Many applications, especially those converted from MyISAM, can set it to a value of 2, which means that the log is not flushed to disk, but only to the operating system's cache. The log is still flushed to disk every second, so the consumption of 1-2 updates per second is usually not lost. Setting it to 0 is much faster, but also relatively insecure - some transactions are lost when the MySQL server crashes. Set to 2 to instruct to miss that part of the transaction flushed to the OS cache.

max_allowed_packet = 4M
thread_stack = 256K
table_cache = 128K
sort_buffer_size = 6M #Query
the buffer size that can be used when sorting. Note: The allocated memory corresponding to this parameter is exclusive to each connection! If there are 100 connections, then the total sort buffer size actually allocated is 100 × 6 = 600MB. Therefore, it is recommended to set 6-8M for servers with about 4GB of memory.

read_buffer_size = 4M #Buffer
size that can be used by read query operations. Like sort_buffer_size, the allocated memory corresponding to this parameter is also exclusive to each connection!

join_buffer_size = 8M
#The size of the buffer that can be used by the joint query operation. Like sort_buffer_size, the allocated memory corresponding to this parameter is also exclusive to each connection!

myisam_sort_buffer_size = 64M
table_cache = 512 #The
overhead of opening a table may be large. For example, MyISAM puts the MYI header to indicate that the table is in use. You definitely don't want to do this too often, so you usually want to increase the number of caches enough to maximize the cache of open tables. It needs to use the resources and memory of the operating system, which is certainly not a problem for the current hardware configuration. If you have more than 200 tables, it may be appropriate to set it to 1024 (each thread needs to open the table), if the number of connections is relatively large, then increase its value. I've seen it set to 100,000.

thread_cache_size = 64 #Thread
creation and destruction can be expensive, as each thread's connect/disconnect is required. I usually set at least 16. If the application has a lot of hopping concurrent connections and the value of Threads_Created is relatively large, then I will increase its value. Its purpose is to eliminate the need to create new threads during normal operations.

query_cache_size = 64M #Specify
the size of the MySQL query buffer. This can be observed by executing the following command in the MySQL console:

# > SHOW VARIABLES LIKE '%query_cache%';
# > SHOW STATUS LIKE 'Qcache%';
# 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 very large, it indicates that the query cache uses Very frequent, if the value is small, it will affect the efficiency, then you can consider not to query the buffer; Qcache_free_blocks, if the value is very large, it indicates that there are many fragments in the buffer.

tmp_table_size = 256M
max_connections = 768 #Specify
the maximum number of connection processes allowed by MySQL. If the error prompt of Too Many Connections often appears when visiting the forum, you need to increase the value of this parameter.

max_connect_errors = 10000000
wait_timeout = 10 #Specify
the maximum connection time for a request, which can be set to 5-10 for servers with about 4GB of memory.

thread_concurrency = 8 #The
value of this parameter is the number of logical CPUs of the server × 2. In this example, the server has 2 physical CPUs, and each physical CPU supports HT hyperthreading, so the actual value is 4 × 2 = 8

skip-networking #Enable
this option to completely disable MySQL's TCP/IP connection mode. If the WEB server accesses the MySQL database server through a remote connection, do not enable this option! Otherwise, it will not be able to connect normally!

The meaning of the show status command
is as follows:
aborted_clients Number of illegally disconnected client connections
aborted_connects Number of failed connections to mysql
com_xxx Number of xxx command executions, there are many
connections Number of connections to mysql
Created_tmp_disk_tables Temporary table created on disk
Created_tmp_tables Temporary table created in memory
Created_tmp_files Temporary Number of files
Key_read_requests The number of requests to read a key block from the cache
Key_reads The number of physical reads of a key block from disk
Max_used_connections Number of connections used at the same time
Open_tables Open tables
Open_files Open files
Opened_tables Open tables
Questions Submitted to the server The number of queries
Sort_merge_passes If this value is large, the sort_buffer value in my.cnf should be increased
The number of seconds that the Uptime server has worked

Suggestions for improving performance:
1. If the open_tables is too large, the table_cache in my.cnf should be larger
. 2. If the Key_reads is too large, the key_buffer_size in my.cnf should be larger. You can use Key_reads/Key_read_requests to calculate the cache failure rate
3. If Handler_read_rnd is too large, many queries in the SQL statement you write will scan the entire table instead of the key of the index.
4. If Threads_created is too large, increase the value of thread_cache_size in my.cnf. Yes Use
Threads_created /Connections to calculate the cache hit rate

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325503100&siteId=291194637