mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了。 造成这样的原因一般是sql操作的时间过长,或者是传送的数据太大(例如使用insert … values的语句过长, 这种情况可以通过修改max_allowed_packed的配置参数来避免,也可以在程序中将数据分批插入)。 产生这个问题的原因有很多,总结下网上的分析: 原因一. MySQL 服务宕了 判断是否属于这个原因的方法很简单,进入mysql控制台,查看mysql的运行时长 mysql> show global status like 'uptime'; +—————+———+ | Variable_name | Value | +—————+———+ | Uptime | 3414707 | +—————+———+ 1 row in set或者查看MySQL的报错日志,看看有没有重启的信息 如果uptime数值很大,表明mysql服务运行了很久了。说明最近服务没有重启过。 如果日志没有相关信息,也表名mysql服务最近没有重启过,可以继续检查下面几项内容。 原因二. mysql连接超时 即某个mysql长连接很久没有新的请求发起,达到了server端的timeout,被server强行关闭。 此后再通过这个connection发起查询的时候,就会报错server has gone away (大部分PHP脚本就是属于此类) mysql> show global variables like '%timeout'; +—————————-+———-+ | Variable_name | Value | +—————————-+———-+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | innodb_lock_wait_timeout | 50 | | innodb_rollback_on_timeout | OFF | | interactive_timeout | […]
View Detailsnginx使用proxy模块时,默认的读取超时时间是60s。 1. send_timeout syntax: send_timeout the time default: send_timeout 60 context: http, server, location Directive assigns response timeout to client. Timeout is established not on entire transfer of answer, but only between two operations of reading, if after this time client will take nothing, then nginx is shutting down the connection. 2. 负载均衡配置时的2个参数:fail_timeout和max_fails 这2个参数一起配合,来控制nginx怎样认为upstream中的某个server是失效的当在fail_timeout的时间内,某个server连接失败了max_fails次,则nginx会认为该server不工作了。同时,在接下来的 fail_timeout时间内,nginx不再将请求分发给失效的server。 个人认为,nginx不应该把这2个时间用同一个参数fail_timeout来控制,要是能再增加一个fail_time,来控制接下来的多长时间内,不再使用down掉的server就更好了~ 如果不设置这2个参数,fail_timeout默认为10s,max_fails默认为1。就是说,只要某个server失效一次,则在接下来的10s内,就不会分发请求到该server上 3. proxy模块的 proxy_connect_timeout syntax: proxy_connect_timeout timeout_in_seconds context: http, server, location This directive assigns a timeout for the connection to the proxyserver. This is not the time until the server returns the pages, this is the […]
View Details