question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't connect to a local, existing MySQL DB

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google “How to X in SQLModel” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Optional

from sqlmodel import Field, Session, SQLModel, create_engine, select


class RealWordEN(SQLModel, table=True):
    id: int = Field(primary_key=True)
    string: str
    type: Optional[str]
    number: Optional[str]
    tense: Optional[str]

    __tablename__ = "real_words_EN"


engine = create_engine("mysql+mysql://root:root@localhost:8889/words", echo=True)
# engine = create_engine("mysql://root:root@localhost:8889/words", echo=True)


with Session(engine) as session:
    statement = select(RealWordEN)
    words = session.exec(statement)

Description

I’ve been trying to interact with an existing MySQL DB. When I try the run this code I get the following error message:

raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql.mysql

I also tried with th DB URL format: engine = create_engine("mysql://root:root@localhost:8889/words", echo=True). In that case, I get a different error message:

ModuleNotFoundError: No module named 'MySQLdb'

Is there some MySQL connection Python module that needs to be installed as well along sqlmodel? I’ve been trying with installing pymysql, aiomysql, with similar errors.

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.6

Python Version

3.9

Additional Context

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
invokermaincommented, Apr 14, 2022

For the record, I didn’t mean it’s not being actively maintained as such, but its only at ver 0.0.6, with 64 open pull requests. Some fix simple bugs and have been sat there for 6 months without anyone looking at them. And there hasn’t been a release in 4 months. And you are right that it does seem to be in a pretty good spot.

For what its worth SQLModel does make the whole FastAPI + SQLAlchemy thing a lot nicer, but you can’t side step really knowing SQLAlchemy. The alternative is to define separate Pydantic and SQLAlchemy models for basically the same thing. Also the type hinting in this library is really nice.

I’d say stick with it

1reaction
mbayabocommented, Apr 6, 2022

Hello,

I just tried to recreate your issue. It seems like mysqlclient is the only connector that I can get to work using:

engine = create_engine("mysql://root:root@localhost:8889/words", echo=True)

Unfortunately, I couldn’t find any recommended connector in the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4.22 Troubleshooting Problems Connecting to MySQL
You can fix this by setting up an account for the combination of client host name and user name that you are using...
Read more >
Cannot connect to Database server (mysql workbench)
click Mange Server Instances (bottom right corner). click Connection. in the Connection box select: Local Instance ($ServerName) ...
Read more >
How Do I Fix “Can't Connect to Local MySQL Server Through ...
First and foremost, you need to head to the Database Manager section of our Control Panel and click on the database that you...
Read more >
Troubleshooting Connection Issues - MariaDB Knowledge Base
Problems Exporting Query Results · Access to the Server, but not to a Database · Option Files and Environment Variables · Unable to...
Read more >
How to Connect to MySQL Server - Devart Blog
Locate the MySQL Command-Line Client · Run the client · Enter your password · Get a list of databases · Create a database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found