zhongjiajie commented on a change in pull request #6576: [AIRFLOW-5922] Add 
option to specify the mysql client library used in MySqlHook
URL: https://github.com/apache/airflow/pull/6576#discussion_r389352023
 
 

 ##########
 File path: airflow/providers/mysql/hooks/mysql.py
 ##########
 @@ -113,8 +107,44 @@ def get_conn(self):
             conn_config['unix_socket'] = conn.extra_dejson['unix_socket']
         if local_infile:
             conn_config["local_infile"] = 1
-        conn = MySQLdb.connect(**conn_config)
-        return conn
+        return conn_config
+
+    def _get_conn_config_mysql_connector_python(self, conn):
+        conn_config = {
+            'user': conn.login,
+            'password': conn.password or '',
+            'host': conn.host or 'localhost',
+            'database': self.schema or conn.schema or '',
+            'port': int(conn.port) if conn.port else 3306
+        }
+
+        if conn.extra_dejson.get('allow_local_infile', False):
+            conn_config["allow_local_infile"] = True
+
+        return conn_config
+
+    def get_conn(self):
+        """
+        Establishes a connection to a mysql database
+        by extracting the connection configuration from the Airflow connection.
+
+        .. note:: By default it connects to the database via the mysqlclient 
library.
+            But you can also choose the mysql-connector-python library which 
lets you connect through ssl
+            without any further ssl parameters required.
+
+        :return: a mysql connection object
+        """
+        conn = self.connection or self.get_connection(self.mysql_conn_id)  # 
pylint: disable=no-member
+
+        client_name = conn.extra_dejson.get('client', 'mysqlclient')
 
 Review comment:
   Looking good! 👍 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to