Skip to content

MySqlHook add support for init_command #33300

Description

@alexbegg

Description

There is currently no way to pass an init_command connection argument for a mysql connection when using either the mysqlclient or mysql-connector-python libraries with the MySql provider's MySqlHook.

Documentation for connection arguments for mysqlclient library, listing init_command:
https://mysqlclient.readthedocs.io/user_guide.html?highlight=init_command#functions-and-attributes

Documentation for connection arguments for mysql-connector-python library, listing init_command:
https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html

There can be many uses for init_command, but also what comes to mind is why do we explicitly provide support to certain connection arguments and not others?

Use case/motivation

For my own use right now I am currently am subclassing the hook and then altering the connection arguments to pass in init_command to set the time_zone session variable to UTC at connection time, like so:

conn_config['init_command'] = r"""SET time_zone = '+00:00';"""

Note: This is just an example, there can be many other uses for init_command besides the example above. Also, I am aware there is a time_zone argument for connections via the mysql-connector-python library, however that argument is not supported by connections made with mysqlclient library. Both libraries do support the init_command argument.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. changed the title [-]MySqlHook init_command[/-] [+]MySqlHook add support for init_command[/+] on Aug 11, 2023
  2. alexbegg commented on Aug 12, 2023

    @alexbegg
    ContributorAuthor

    I am working on a PR for this, I just need to make sure the tests pass and if a test DAG covering my example use case works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions