Hi, I'm trying to connect to a MySQL database and ...
# ask-community
j
Hi, I'm trying to connect to a MySQL database and am receiving an error that there is no MySQL model. The
mysqlclient
Anaconda package won't run on my version of Python 3.8.8 but when I created a second conda environment on 3.7 I was told that it had a compatibility error with Prefect. Are there alternative ways to connect to a MySQL db using secrets & SSL args?. The specific error is:
Error during execution of task: ModuleNotFoundError("No module named 'MySQLdb'")
k
Hey @Jason Motley , the current MySQL task seems to support secrets and SSL. Does pymysql not work for you?
j
I'm copying what my team is doing (they are on macs, I'm on a Lenovo). We call
sqlalchemy
to create a database engine
create_engine
in the task... let me provide a generic example
Copy code
@task(log_stdout=True)
def db_connection(credentials: dict) -> any:
    import sqlalchemy as db
    ssl_args = {args}
    user = credentials['username']
    password = credentials['password']
    url = 'Our URL'
    port = 1111
    engine = db.create_engine(
        f'mysql://{user}:{password}@{url}:{port}/?charset=utf8', 
        connect_args=ssl_args
    )
    return engine
The issue so far as i can see it is in the
db.create_engine
section
that said I'm open to rewriting this using a different package if I can manage it
k
You mean the
db.create_engine
is the one raising the
ModuleNotFoundError
?
j
Correct
I'd assume that is causing it, given that i"m not calling MySQLdb anywhere else and its the only place "MySQL" is mentioned
k
Are you use it’s compatible with Python 3? Have you seen this ?
j
I believe it's compatible with Python 3. Everyone else at the company has Python 3 and is able to use prefect. I'll try to reconfigure the task per the above post though
The thing I'm confused by is that I never use a mysqldb package at any point..
k
Gotcha I have not used that library myself. Just have experience with pymysql