Document directory
Source: http://www.eygle.com/digest [website technology]
Link: http://www.eygle.com/digest/2007/06/mysql_mycnf.html
For a single running web server, we recommend that you add:
Skip-locking
Skip-name-resolve
Skip-networking
Use "localhost" when connecting to the database in PHP.The mysql client library will overwrite and try to connect to the local socket .(
We can code from PhP. ini:
; Default socket name for local MySQL connects. If empty, uses the built-in; MySQL defaults.mysql.default_socket = /tmp/mysql.sock
By default, Unix accesses/tmp/MySQL. Sock)
- Some options are described as follows:
My. CNF does not exist by default. You can see it in/usr/local/share/MySQL:
- My-huge.cnf
- My-innodb-heavy-4G.cnf
- My-large.cnf
- My-medium.cnf
- My-small.cnf
And other files. copy the files that are suitable for your machine configuration to the/etc/My. CNF or MySQL data directory/My. CNF (/var/DB/MySQL) or ~ /. My. CNF. Detailed descriptions are provided in the file.
[Mysqld]
Port = 3306
Serverid = 1
Socket =/tmp/MySQL. Sock
Skip-locking
# Avoid external locks of MySQL to reduce the chance of errors and enhance stability.
Skip-name-resolve
Prohibit MySQL from performing DNS resolution on external connections. This option can eliminate the time for MySQL to perform DNS resolution. However, if this option is enabled, IP addresses are required for all remote host connection authorizations. Otherwise, MySQL cannot process connection requests normally!
Back_log = 384
Specify the number of possible MySQL connections. When the MySQL main thread receives many connection requests within a short period of time, this parameter takes effect. The main thread takes 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 in the stack within a short time before MySQL temporarily stops responding to a new request. 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 listener queue for the incoming TCP/IP connection. Different operating systems have their own limits on the queue size.
Trying to set back_log to be higher than your operating system limit will be invalid. The default value is 50. We recommend that you set the value to an integer smaller than 512 in Linux.
Key_buffer_size = 256 m
# Key_buffer_size specifies the buffer size used for the index. Increasing the size can improve the index processing performance.
This parameter can be set to 384 m or m for servers with around 4 GB of memory.
Note: If this parameter value is set too large, the overall efficiency of the server will be reduced!
Max_allowed_packet = 4 m
Thread_stack = 256 K
Table_cache = 128 K
Sort_buffer_size = 6 m
The buffer size that can be used to query sorting. Note: The allocated memory corresponding to this parameter is exclusive to each connection! If there are 100 connections, the total size of the actually allocated sort buffer is 100 × 6 = 600 mb. Therefore, we recommend that you set the size of a server with around 4 GB to 6-8 Mb.
Read_buffer_size = 4 m
The buffer size that can be used by the read query operation. Like sort_buffer_size, the allocated memory corresponding to this parameter is exclusive to each connection!
Join_buffer_size = 8 m
The buffer size that can be used by the Joint query operation. The same as sort_buffer_size, the allocated memory corresponding to this parameter is exclusive to each connection!
Myisam_sort_buffer_size = 64 m
Table_cache = 512
Thread_cache_size = 64
Query_cache_size = 64 m
Specify the size of the MySQL Query Buffer. You can run the following command on the MySQL console to observe the Code:
# > SHOW VARIABLES LIKE '%query_cache%';# > SHOW STATUS LIKE 'Qcache%';
If the qcache_lowmem_prunes value is very large, it indicates that there is often insufficient buffer;
If the qcache_hits value is very large, it indicates that the query buffer is used very frequently. If the value is small, it will affect the efficiency, you can consider not to use the Query Buffer; qcache_free_blocks, if the value is very large, it indicates that there are many fragments in the buffer.
Tmp_table_size = 256 m
Max_connections = 768
Specifies the maximum number of connection processes allowed by MySQL. If the too connector connections error is frequently reported during Forum access, you need to increase the value of this parameter.
Max_connect_errorrs = 10000000
Wait_timeout = 10
Specify the maximum connection time of a request. For servers with around 4 GB of memory, you can set it to 5-10.
Thread_concurrency = 8
In this example, the server has two physical CPUs, and each physical CPU supports h.t hyper-threading, therefore, the actual value is 4x2 = 8.
Skip-networking
Enabling this option can completely disable the MySQL TCP/IP connection mode. If the Web server accesses the MySQL database server remotely, do not enable this option! Otherwise, the connection will fail!