Python Forum
Python MYSQL connection does not work after 1h idle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python MYSQL connection does not work after 1h idle
#7
(Oct-06-2021, 05:21 AM)zazas321 Wrote:
(Oct-05-2021, 03:11 PM)tomtom Wrote: I used to have similar problem with mysql database. when I used with a windows server, I search and search but didn't find a solution on it, so what I did was to create a function that connect to the mysql db and call it any time I want to make a query to the dp. That is how I solved my own

these is the example:
def connect_to_db(): # function connect to database
    return mysql.connector.connect(host="localhost",
                                   user="root",
                                   passwd="",
                                   database="lookup_bot")


Yes, that is what I did but have not find any bug on it

Then I do this whenever I want to make a query:
mydp = connect_to_db()
my_cursor = mydp.cursor(buffered=True)


Thanks for the reply. Can you explain what the code does? Do you make a new connection everytime you want to perform a query? If so, that does not seem like a good solution?
The problem for me is that after 1 hour of idling, the connection is still active and I can see the connection on the processlist as I have shown before. Even though the connection is still active, it wont let me do any queries.

As a temporary solution, I have some function that is being executed every 10 minutes which performs some query to my database to ensure that the connection does not idle for too long. That seems to work however that is not an optimal solution
Reply


Messages In This Thread
RE: Python MYSQL connection does not work after 1h idle - by tomtom - Oct-06-2021, 04:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why can I not see the code correctly in Python IDLE.? Trump 8 751 Apr-04-2024, 07:47 AM
Last Post: jonesphedra
  I don't know what is wrong (Python and SQL connection) shereen 3 414 Apr-01-2024, 08:56 AM
Last Post: Pedroski55
  No Internet connection when running a Python script basil_555 8 701 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 378 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 402 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  connection python and SQL dawid294 4 727 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Mysql and mysql.connector error lostintime 2 728 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 759 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Launch Python IDLE Shell from terminal Pavel_47 5 1,291 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Python Idle won't start totalmachine 9 3,607 Oct-16-2022, 05:57 PM
Last Post: totalmachine

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020