I'm trying to connect to my database with sqlAlchemy and get the error Can't load plugin: sqlalchemy.dialects:mysql.pymysql
. The script worked before and I didn't change anything, tho I can't connect to the db.
I'm importing the libraries:
#from sqlalchemy import *
from sqlalchemy import create_engine, Table, Column, Integer, String, DateTime, Float, MetaData
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *
from pybigquery.api import ApiClient
My connection:
# Database parameter
host = "127.0.0.1"
user = "someUser"
passwd = "somePassword"
database = "ucb-pvapp"
# Database connection
db=pymysql.connect(
host=host,
user=user,
passwd=passwd,
db=database,
autocommit=True)
engine = create_engine(f'mysql+pymysql://{user}:{passwd}@{host}/{database}')
cursor=db.cursor()
sqlAlchemy and pymysql are installed.
Using Ubuntu 20.04, python 3.8.5 and sqlalchemy Version 1.3.12. Complete traceback:
Traceback (most recent call last):
File "pv.py", line 131, in <module>
engine = create_engine(f'mysql+pymysql://{user}:{passwd}@{host}/{database}')
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/strategies.py", line 61, in create
entrypoint = u._get_entrypoint()
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/url.py", line 172, in _get_entrypoint
cls = registry.load(name)
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/langhelpers.py", line 268, in load
raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql.pymysql
Removing pymysql
and installing it again solved the problem.