title: Correct way of keeping mysql connection
body: <p>I have an application running 24/7 which uses mysql. Different functions of it use mysql. One way to implement it is to create a global mysql instance in the application like this:</p>
  
  <pre><code>self.db = MySQLdb.connect(
              host=self.settings.MYSQL_HOST_LOCAL,
              user=self.settings.MYSQL_USER,
              passwd=self.settings.MYSQL_PASS,
              db=self.settings.MYSQL_DB,
              use_unicode=True,
              charset="utf8",
          )
  </code></pre>
  
  <p>and execute commands using <code>self.db.execute(...)</code>. By doing this, the application uses 1 connection. The other way is to create connection every time I need to execute a transaction.</p>
  
  <p>Approach 1, prevents the application from creating and deleting connections over and over but it will face "mysql gone away" problem if it stays ideal. Approach 2, doesn't have a problem with "mysql gone away", but it has too much I/O.</p>
  
  <p>I am pretty sure neither these approcaches are the right ones, but what is the right approach?</p>