#Yii Solution: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away


Updated November 30, 2013 ● 3,755 views

This is a short guide to all fellow Yii developers out there or PHP developers in general. It took me a good hour to resolve the issue when all of a sudden, Oauth login is throwing out an error when it's trying to validate against the MySQL database.

The MySQL error is:

[exception.CDbException] exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away'

So obviously, it'a saying that the connection to MySQL has been lost. So this is all about connection timeout. There are several timeout configurations in MySQL.

Searching Google gave me a couple of suggestions from adjusting MySQL configurations such as max_allowed_packet, connect_timeout, etc. Some of the changes didn't workout until I tried to change wait_timeout.

My original wait_timeout was set to 20. I changed it to 60 seconds and it's back to normal again:

wait_timeout=60

0 Comments