def _connect(self):
"""Function connects to the database"""
logger.debug('Connecting to MySQL database.')
try:
if str(self.logsocket).lower() == 'tcp':
self.connection = MySQLdb.connect(
host=self.host,
port=self.port,
user=self.username,
passwd=self.passphrase,
db=self.db)
elif str(self.logsocket).lower() == 'dev':
self.connection = MySQLdb.connect(
unix_socket=self.logdevice,
user=self.username,
passwd=self.passphrase,
db=self.db)
self._create_database()
except (AttributeError, MySQLdb.OperationalError):
logger.exception('Exception: Cannot connect to database.')
评论列表
文章目录