MySQL Variables back_log 数据库 参数变量解释及正确配置使用
本站中文解释
MySQL的 back_log 参数用于指定MySQL服务器的TCP/IP连接队列的大小。这个参数用来确定MySQL服务器可以接受的最大连接数,因为在任何时候,MySQL服务器的进程都在处理客户端的请求,如果一次处理太多请求,就需要增加连接队列大小,如果太少,就会发生超时,许多客户端就不能够连接到MySQL服务器。
通过在MySQL服务器中设置back_log参数,可以确定MySQL服务器可以接受的最大连接数;通常将back_log参数设置为系统最大连接数的2倍,即32个;如果您的服务器连接频繁,您可以将其设置的更大,如64个。
设置back_log参数的方法如下:
第一步:登录mysql服务器,进入mysql终端。
第二步:加载mysql参数变量文件(my.cnf),执行命令:mysql> source my.cnf
第三步:执行命令行:mysql> SET GLOBAL back_log= N 。其中,N为设定的back_log参数值。
第四步:查看设置是否生效,执行命令:mysql> show variables like “back_log”;
第五步:保存修改。执行命令:mysql> service mysql restart 或 重启mysql服务。
官方英文解释
back_log
Command-Line Format | --back-log=# |
---|---|
System Variable | back_log |
Scope | Global |
Dynamic | No |
Type | Integer |
Default Value | -1 (signifies autosizing; do not assign this literal value) |
Minimum Value | 1 |
Maximum Value | 65535 |
The number of outstanding connection requests MySQL can have.
This comes into play when the main MySQL thread gets very many
connection requests in a very short time. It then takes some
time (although very little) for the main thread to check the
connection and start a new thread. The
back_log
value indicates how
many requests can be stacked during this short time before
MySQL momentarily stops answering new requests. You need to
increase this only if you expect a large number of connections
in a short period of time.
In other words, this value is the size of the listen queue for
incoming TCP/IP connections. Your operating system has its own
limit on the size of this queue. The manual page for the Unix
listen()
system call should have more
details. Check your OS documentation for the maximum value for
this variable. back_log
cannot be set higher than your operating system limit.
The default value is based on the following formula, capped to
a limit of 900:
50 + (max_connections / 5)