I have two flask restful API's. Both are working fine. API1 is only for reading the database, API2 deals with update/insert. Both access the same database.
Problem:
API1 stops working every morning and I have to restart it everytime (once in the morning). Error is - MySQL server is gone away.
API2 always work doesn't give any error.
Earlier, I thought wait_timeout (default 8 hours) could be the reason that API1 throws that error. But, why does API2 work then? (I use a class for database operations, and I have connect string in its init method. Also, I do not close any of the database connection. I'll very soon edit to corect it, just giving the info here to know the exact reason for that error)
Question - Why does only API1 gives that error while API2 never?
PS - I asked this on stackoverflow but was advised to post this here, since I never found an answer reposting here
MySQL Config File:
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
bind-address = 127.0.0.1
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover-options = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
query_cache_limit = 1M
query_cache_size = 16M
Error.log
2020-04-02T10:30:13.606051Z 15 [Note] Aborted connection 15 to db: 'databasename' user: 'root' host: 'localhost' (Got an error reading communication packets)
The database class is like this:
import MySQLdb
class Db:
parameters = ("localhost", "root", "password", "databasename")
def __init__(self):
conn = MySQLdb.connect(*self.parameters)
self.cur = conn.cursor()
0 Answers