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:
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",
        )
and execute commands using self.db.execute(...). By doing this, the application uses 1 connection. The other way is to create connection every time I need to execute a transaction.
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.
I am pretty sure neither these approcaches are the right ones, but what is the right approach?