Pylons error - 'MySQL server has gone away'
<p>[I hope this isn't too obscure&hellip; I'll ask the newsgroup if nobody knows here]</p>

<p>I'm using Pylons (a python framework) to serve a simple web application, but it seems to die from time to time, with this in the error log: <code>(2006, 'MySQL server has gone away')</code></p>

<p>I did a bit of checking, and saw that this was because the connections to MySQL were not being renewed. This shouldn't be a problem though, because the <code>sqlalchemy.pool_recycle</code> in the config file should automatically keep it alive. The default was <code>3600</code>, but I dialed it back to <code>1800</code> because of this problem. It helped a bit, but <code>3600</code> <em>should</em> be fine according to the docs. The errors still happen semi-regularly. I don't want to lower it too much though and DOS my own database :).</p>

<p>Maybe something in my MySQL config is goofy? Not sure where to look exactly.</p>

<p>Other relevant details:</p>

<pre><code>  Python 2.5
  Pylons: 0.9.6.2 (w/ sql_alchemy)
  MySQL: 5.0.51
</code></pre>

<p>I think I fixed it. It's turns out I had a simple config error. My ini file read:</p>

<pre><code>sqlalchemy.default.url = [connection string here]
sqlalchemy.pool_recycle = 1800
</code></pre>

<p>The problem is that my <code>environment.py</code> file declared that the engine would only map keys with the prefix: <code>sqlalchemy.default</code> so <code>pool_recycle</code> was ignored.</p>

<p>The solution is to simply change the second line in the ini to:</p>

<pre><code>sqlalchemy.default.pool_recycle = 1800
</code></pre>
