MySQL server has gone away

Hello,

Currently I’m working on Yii2 application that has a lot of console scripts and I encountered a problem with MySQL connection in one of them. It throws an exception “MySQL server has gone away”. Actually it throws that exception if there is no communication between script and database for about 5-7 seconds (script does some background job and if needed should update a table in the database).

I added PDO timeout in db configuration:




'attributes' => [

    PDO::ATTR_TIMEOUT => 600,

],



I also checked MySQL timeout variables:




mysql> show 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        | 259200 |

| net_read_timeout           | 30     |

| net_write_timeout          | 60     |

| slave_net_timeout          | 3600   |

| table_lock_wait_timeout    | 50     |

| wait_timeout               | 259200 |

+----------------------------+--------+

10 rows in set (0.00 sec)



But they look good.

I tried to reconnect by closing and opening connection




Yii::$app->db->close();

Yii::$app->db->open();



but it doesn’t work. It still throws an exception. Do you have any ideas what I’m doing wrong?

Thanks

See if anything in this topic helps you.