feluelle 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_r362945137
##########
File path: airflow/hooks/mysql_hook.py
##########
@@ -114,8 +111,46 @@ 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 ''
+ }
+
+ if not conn.port:
+ conn_config['port'] = 3306
+ else:
+ conn_config['port'] = int(conn.port)
+
+ 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
Review comment:
Because `mysql_conn_id` is only accessible because of `conn_name_attr =
'mysql_conn_id'`
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services