15

I'm trying to replace Databases with SQLAlchemy 1.4 async. When I try to make the engine I get the following error:

sqlalchemy.exc.InvalidRequestError: The asyncio extension requires an async driver to be used. The loaded 'mysqldb' is not async.

I'm making the engine like this:

engine = create_async_engine(SQLALCHEMY_DATABASE_URL, future=True)

What is need to get mysqldb to work with SQLAlchemy async?

1 Answer 1

22

I figured it out, I was using this URL:

'mysql://someuser:passwd1234@localhost/app_db'

But I needed to be using something like:

'mysql+asyncmy://someuser:asswd1234@localhost/app_db'

I was missing the +asyncmy part to use the asyncmy dialect. I needed to install the package too:

pip install sqlalchemy[asyncio]
Sign up to request clarification or add additional context in comments.

5 Comments

Currently (April 2022) asyncmy is preferred over aiomysql
Thanks for your suggestion. I have used pip install asyncmy and when I run my code, it said No module named 'asyncmy'.
@Oscar916 if you are installing on windows, you'll need C++ buildtools to install via pip. See: github.com/long2ice/…
i got same error but pip didn't say i need build tool nor prompt build failures.
but i can solve this error by pip install asyncmy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.