<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>

[{'answer_id': 15261, 'author': 'Jon Bright', 'author_id': 1813, 'author_profile': 'https://Stackoverflow.com/users/1813', 'pm_score': 2, 'selected': False, 'text': "<p>You might want to check MySQL's timeout variables:</p>\n\n<pre><code>show variables like '%timeout%';\n</code></pre>\n\n<p>You're probably interested in <code>wait_timeout</code> (less likely but possible: <code>interactive_timeout</code>).  On Debian and Ubuntu, the defaults are 28800 (MySQL kills connections after 8 hours), but maybe the default for your platform is different or whoever administrates the server has configured things differently.</p>\n\n<p>AFAICT, <code>pool_recycle</code> doesn't actually keep the connections alive, it expires them on its own before MySQL kills them.  I'm not familiar with pylons, but if causing the connections to intermittently do a <code>SELECT 1;</code> is an option, that will keep them alive at the cost of basically no server load and minimal network traffic.  One final thought: are you somehow managing to use a connection that pylons thinks it has expired?</p>\n"}, {'answer_id': 46442, 'author': 'swilliams', 'author_id': 736, 'author_profile': 'https://Stackoverflow.com/users/736', 'pm_score': 4, 'selected': True, 'text': "<p>I think I fixed it. It's turns out I had a simple config error. My ini file read:</p>\n\n<pre><code>sqlalchemy.default.url = [connection string here]\nsqlalchemy.pool_recycle = 1800\n</code></pre>\n\n<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>\n\n<p>The solution is to simply change the second line in the ini to:</p>\n\n<pre><code>sqlalchemy.default.pool_recycle = 1800\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/8154', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/736/']