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()
的な再接続系のメソッドが無いので、自作する必要があるところが残念。