Answer the question
In order to leave comments, you need to log in
Do I need to close the database connection?
Hello. I am writing a python program and using mysql connector.
I will have a lot of calls to the database in my program, but the program will also run for hours and no one will work in it.
Whether prompt it is necessary to close connection after each SQL request? For example like this:
conn = MySQLConnection("Данные для соединения")
cursor = conn.cursor()
cursor.execute("SELECT * FROM avi_db")
row = cursor.fetchall()
cursor.close()
conn.close()
Answer the question
In order to leave comments, you need to log in
If the application is a daemon, then it is better to reuse it. If each request raises a new process, then you can not close it, because. all connections will be cut off as soon as the request is processed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question