A
A
Anna2017-03-18 22:35:02
linux
Anna, 2017-03-18 22:35:02

How to prevent the server from closing the connection to the database?

Good day. There is a server in Java, running under Ubuntu. I encountered a fairly common problem - after a certain time, the connection to the Mysql database is closed and does not allow anything to be put / taken away. Advises to set autoReconnect=true in JDBC properties, which doesn't help.
Further actions: I try to run a python program as a background process that pings the server every 10 minutes. Also doesn't help.

from commands import getoutput
from time import sleep
import re
import os

host='мой сервер'

interval1=600
interval2=600
p = re.compile('ttl=')

while True:   
    ping=getoutput('ping -c 2 %s' % host)
    if not p.findall(ping):
        print "Attempt to connect failed" 
        sleep(interval2)
    sleep(interval1)

Then I try not just to ping, but to make sure that the program really loads data every 10 minutes.
response = urllib.urlopen(host)
And here I get Python socket.error: connection refused .
Advise something, or how to fix the program in python, or how else can I figure out the connection to the database?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene Khrustalev, 2017-03-18
@eugenehr

Use pool connections. There are a million settings and you don't need to ping anything.

D
Dimonchik, 2017-03-18
@dimonchik2013

ping to the database in no way (well, except for checking the availability of the piece of iron)
pick the Java connector, it's very strange that it closes itself

P
Puma Thailand, 2017-03-19
@opium

use connection pool
ping is useless at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question