title: what is the best solutions to mysql connection timeout?
body: <p>I am writing a small web app in Go, which uses mysql to store data. </p>
  
  <p>I got intermittent mysql error if the web sever didn't get any request after some amount of time(> 8 hours):</p>
  
  <pre><code>[mysql] 2017/02/08 16:31:56 packets.go:33: unexpected EOF
  [mysql] 2017/02/08 16:31:56 packets.go:130: write tcp 127.0.0.1:49188-&gt;127.0.0.1:3306: write: broken pipe
  </code></pre>
  
  <p>I found some related discussion on github(<a href="https://github.com/go-sql-driver/mysql/issues/529" rel="nofollow noreferrer">issue 529</a>, <a href="https://github.com/go-sql-driver/mysql/issues/257" rel="nofollow noreferrer">issue 257</a> and <a href="https://github.com/go-sql-driver/mysql/issues/446" rel="nofollow noreferrer">issue 446</a>). From what I understand, mysql db would close the connection if timeout is reached.</p>
  
  <p>I tried to set <code>SetMaxOpenConns</code> to 9 and <code>SetMaxIdleConns</code> to 0 as some people recommended. However, this threw exception immediately. (But if I set <code>SetMaxIdleConns</code> larger than 0, there was no immediate exception thrown)</p>
  
  <p>I also tried to set <code>SetConnMaxLifetime</code> to 5 mins. This threw exception too after 5 mins. </p>
  
  <p>Now I am trying the code below:</p>
  
  <pre><code>db.SetConnMaxLifetime(0)
  db.SetMaxOpenConns(10)
  db.SetMaxIdleConns(5)
  </code></pre>
  
  <p>It has been running for 20 mins. It's still too early to tell.
  (UPDATE: this doesn't work either)</p>
  
  <p>Here is configuration:</p>
  
  <ul>
  <li>driver: go-sql-driver V1.3.  </li>
  <li>go version: go1.7.1 darwin/amd64</li>
  <li>mysql: <a href="https://hub.docker.com/_/mysql/" rel="nofollow noreferrer">latest from docker hub</a></li>
  <li>rkt version: 1.18</li>
  <li>CoreOS: 1284.0.0</li>
  </ul>