Reputation: 29
I am using python 3.6 within Anaconda. I am trying to connect to mySQL 5.7 through SQLAlchemy as mysql.connector flavor='mysql' is deprecated in the newest version.(I am able to connect to the database when I use python 3.4 and am able to use the flavor=mysql optoin to do inserts into the database through pandas).
I am trying to do the same via this SQLAlchemy engine method. But I am not able to connect.
Here is my code:
import sqlalchemy as sa
engine= sa.create_engine("mysql+mysqldb://user:password@localhost/databasename")
I get the following error:
ModuleNotFoundError: No module named 'MySQLdb'
Please help.
Thanks!
Upvotes: 1
Views: 2350
Reputation: 111
This is extremely late in the game, I had the same issue with python3 and Flask-SQLAlchemy.
I fixed this by installing pymysql in my virtualenv
pip install pymysql
And then use the database_uri as
'mysql+pymysql://{username}:{password}@{host}:{port}/{db_name}'
instead of
'mysql+mysqldb...'
Upvotes: 4