Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support aiomysql (create_async_engine & async_creator) for async connector like postgress? #883

Closed
rjjan opened this issue Nov 1, 2023 · 6 comments
Assignees
Labels
type: question Request for information or clarification.

Comments

@rjjan
Copy link

rjjan commented Nov 1, 2023

Question

I use connector to Cloud SQL mysql
can i use aiomysql just like [asyncpg] (PostgreSQL)
just like
"Async Driver Usage" section in https://pypi.org/project/cloud-sql-python-connector/
Thank you

Code

No response

Additional Details

No response

@rjjan rjjan added the type: question Request for information or clarification. label Nov 1, 2023
@jackwotherspoon
Copy link
Collaborator

Hi @rjjan, thanks for asking a question on the Cloud SQL Python Connector 😄

Unfortunately the Cloud SQL Python Connector does not currently support the aiomysql library, thus it will not work the same as asyncpg's async driver usage.

There is an open tracking issue #216 on our repo for its support. We also have a WIP PR open but it is blocked and has been blocked for a while on an aiomysql feature PR.

If you are using a Cloud SQL instance with a Private IP you could connect directly with aiomysql to your instance and not use this connector library. If that is something that interests you let me know and I can show you how to do it securely using an SSL connection and connecting directly to your instance.

@rjjan
Copy link
Author

rjjan commented Nov 2, 2023

Hi @jackwotherspoon

Really appreciate your answer. Unfortunately I am using public IP Cloud SQL instance.

Seems that either I need to switch from mysql to postgress or to modify code to not using async engine. (a bit headache)

Thanks

@jackwotherspoon
Copy link
Collaborator

@rjjan If you are using Public IP than you could deploy the Cloud SQL Proxy alongside your application and continue to use aiomysql. That would probably be the path of least resistance for you. Where are you connecting from? Cloud Run? App Engine? Local machine?

@rjjan
Copy link
Author

rjjan commented Nov 2, 2023

@jackwotherspoon It's an api service. I plan to deploy it to Cloud Run.
Currently I had this async issue when testing this container from local.
I haven't tried Cloud SQL Proxy but I'll look into it.
I was thinking Cloud Language Connector is the best practice to connect to Cloud SQL. Any penalty if I go with Cloud SQL Auth Proxy ?

Thanks again.

@jackwotherspoon
Copy link
Collaborator

jackwotherspoon commented Nov 2, 2023

I was thinking Cloud Language Connector is the best practice to connect to Cloud SQL. Any penalty if I go with Cloud SQL Auth Proxy ?

@rjjan No penalty to using the Proxy other than a bit more configuration, the Cloud SQL Proxy is a language agnostic version of the Python Connector essentially.

For Cloud Run I would recommend deploying the Cloud SQL Proxy as a sidecar using Cloud Run's multi-container feature. We have a Ruby example in our Cloud SQL Proxy repo that you can basically use the exact same YAML for your Python application. Just change the port to 3306 for MySQL and then you can have your Python application connect to your Cloud SQL instance via 127.0.0.1:3306 as if it were a localhost connection.

Hope this helps lay the ground work for you 😄

@jackwotherspoon
Copy link
Collaborator

Going to close this as answered, feel free to re-open if issues persist 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification.
Projects
None yet
Development

No branches or pull requests

2 participants