コード例 #1
0
 def _initialize_connection(self):
     try:
         LOG.debug('Trying connection to the MySQL database {}',
                   self.database)
         self.conn = mysql.connector.connect(**self.config)
         if self.conn.is_connected():
             db_info = self.conn.get_server_info()
             LOG.debug(
                 'MySQL database connection was successful (MySQL server ver. {})',
                 db_info)
     except mysql.connector.Error as exc:
         if exc.errno == 1049 and not self.is_connection_test:
             # Database does not exist, create a new one
             try:
                 db_create_mysql.create_database(self.config.copy())
                 self._initialize_connection()
                 return
             except mysql.connector.Error as e:
                 LOG.error('MySql error {}:', e)
                 if e.errno == 1115:  # Unknown character set: 'utf8mb4'
                     # Means an outdated MySQL/MariaDB version in use, needed MySQL => 5.5.3 or MariaDB => 5.5
                     raise DBMySQLError(
                         'Your MySQL/MariaDB version is outdated, consider an upgrade'
                     ) from e
                 raise DBMySQLError(str(e)) from e
         LOG.error('MySql error {}:', exc)
         raise DBMySQLConnectionError from exc
     finally:
         if self.conn and self.conn.is_connected():
             self.conn.close()
コード例 #2
0
 def _initialize_connection(self):
     try:
         common.debug('Trying connection to the MySQL database {}'.format(
             self.database))
         self.conn = mysql.connector.connect(**self.config)
         if self.conn.is_connected():
             db_info = self.conn.get_server_info()
             common.debug(
                 'MySQL database connection was successful (MySQL server ver. {})'
                 .format(db_info))
     except mysql.connector.Error as e:
         if e.errno == 1049 and not self.is_connection_test:
             # Database does not exist, create a new one
             try:
                 db_create_mysql.create_database(self.config.copy())
                 self._initialize_connection()
                 return
             except mysql.connector.Error as e:
                 common.error("MySql error {}:".format(e))
                 raise MySQLConnectionError
         common.error("MySql error {}:".format(e))
         raise MySQLConnectionError
     finally:
         if self.conn and self.conn.is_connected():
             self.conn.close()