关于mysql连接错误:No operations allowed after connection closed

     写了一个web项目后部署到服务器,第二天登录时网页出现报错信息。

No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error: ** BEGIN NESTED EXCEPTION ** 
com.mysql.jdbc.CommunicationsException MESSAGE: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION **
java.net.SocketException MESSAGE: Broken pipe (Write failed) STACKTRACE: 
java.net.SocketException: Broken pipe (Write failed) at 
java.net.SocketOutputStream.socketWrite0(Native Method) at 
java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) at 

      这里只截取一部分,基本是上连接不上数据库造成的。

      查询原因发现,Mysql服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection。那么只需要修改配置信息中的wait_time即可。

      从网上找到很多解决方案都不奏效。这里说一下我的解决方案。

      首先找到mysql的配置文件,我是用的linux系统,rmp方式安装的mysql,mysql的配置文件的默认路径在/etc/my.cnf。

在mysqlid后的插入要修改的配置信息,wait_time和interactive_timeout就是用来配置等待时间的,我这里设置的等待时间为7天。

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
wait_timeout=604800
interactive_timeout=604800
event_scheduler=on

      然后在控制台输入source /etc/my.cnf,最后重启mysql服务即可service mysql restart。

   

遇到的问题

        之前只在配置信息中,只在配置信息最后面,修改了wait_time和interactive_timeout两个参数,如下图所示

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
interactive_timeout = 604800
wait_timeouot = 604800

      结果是重启mysql服务时则会报错,
Starting MySQL...The server quit without updating PID file [FAILED]b/mysql/iZ8vbb11xfgg1bsbv6e19mZ.pid).

 

你可能感兴趣的:(关于mysql连接错误:No operations allowed after connection closed)