mysqlの穴
1985 ワード
エラーコード
の原因となる
MySQLサーバーのデフォルトの「wait_timeout」は28800秒で8時間です.つまり、1つの接続の空き時間が8時間を超えると、MySQLは自動的に接続を切断しますが、接続プールは接続が有効であると判断します(接続の有効性は検証されていません).この接続を申請する必要がある場合、上記のエラーが発生します.
解決策
mysqlのプロファイルを変更しますmy.cnfこのファイルはmysqlのインストールディレクトリまたは/etc/myで一般的です.cnf
修正内容は以下のようにタイムアウト時間を1年に変更
保存を変更したらmysqlを再起動します
そして観察しましょう
Unexpected error occurred in scheduled task.
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection
for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
No operations allowed after connection closed.
。。。。。。
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed
after connection closed.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
。。。。。。
org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(
DataSourceTransactionManager.
java:223)
... 22 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 59,942 milliseconds ago.
The last packet sent successfully to the server was 24 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
。。。。。。
org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(
DataSourceTransactionManager.
java:212)
... 22 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read
0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2914)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3332)
の原因となる
MySQLサーバーのデフォルトの「wait_timeout」は28800秒で8時間です.つまり、1つの接続の空き時間が8時間を超えると、MySQLは自動的に接続を切断しますが、接続プールは接続が有効であると判断します(接続の有効性は検証されていません).この接続を申請する必要がある場合、上記のエラーが発生します.
解決策
mysqlのプロファイルを変更しますmy.cnfこのファイルはmysqlのインストールディレクトリまたは/etc/myで一般的です.cnf
修正内容は以下のようにタイムアウト時間を1年に変更
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
保存を変更したらmysqlを再起動します
そして観察しましょう