mysql连上一段时间连不上报错了,
(2003, "Can't connect to MySQL server on '192.168.60.172' (99)")
此类错误是连接数超过设定的限制引起
检查到代码如下:
class PathProperty(object):
def __init__(self,place, path=''):
self.path = path
self.place = place
self.mysqldb = mysql_connect()
def get_state(self):
quary_sql = 'select state from cmdb_test.path_info_history where path= \'{}\' and site=\'{}\''.format(self.path,self.place)
con = self.mysqldb.select(quary_sql)
data = con.fetchone()
return data[0]
def get_path(self):
quary_sql = 'select path from cmdb_test.path_info_history where site=\'{}\''.format(self.place)
con = self.mysqldb.select(quary_sql)
data = con.fetchone()
return data[0]
def get_company(self,):
quary_sql = 'select company from cmdb_test.path_info_history where path= \'{}\' and site=\'{}\''.format(self.path, self.place)
con = self.mysqldb.select(quary_sql)
data = con.fetchone()
return data[0]
此类中在初始化进行了连接mysql动作,导致多次实例化类,造车循环中多次链接.
由此,在类__init__加动作操作时危险的.