0
1

More than 3 years have passed since last update.

MySQL server has gone away の時は wait_timeout

Last updated at Posted at 2020-03-09

connect_timeout と毎回間違えるのでメモ・・・

バッチ処理などで下記のエラーが出て MySQL との接続が切れた場合。

HY000 2013 MySQL server has gone away

タイムアウト系の設定で関係があるのは wait_timout

設定値の確認

show global variables like 'wait_timeout';
MariaDB [(none)]> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 10    |
+---------------+-------+
1 row in set (0.01 sec)

設定変更

set global wait_timeout = 120;

global つけるとサーバー自体の設定が変わってしまうので、スクリプト内でだけ変更したいとかなら、global なしで。

set wait_timeout = 120;

pdo ならこんな感じ。

$pdo->query("set wait_timeout = 120");

pdo は mysqli::ping() 的な再接続系のメソッドが無いので、自作する必要があるところが残念。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1