I get the error sqlalchemy.exc.NotSupportedError: (mysql.connector.errors.NotSupportedError) Authentication plugin https://stackoverflow.com/questions/57459623/does-sqlalchemy-support-caching-sha2-password-if-yes-then-how?noredirect=1&lq=1'caching_sha2_password' is not supported
, when I run the following code snippet:
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
# Define the MySQL engine using MySQL Connector/Python
engine = sqlalchemy.create_engine(
'mysql+mysqlconnector://pyuser:Py@pp4Demo@localhost:3306/sqlalchemy', connect_args={'auth_plugin':'mysql_native_password'}, echo=True)
# Define and create the table
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
name = sqlalchemy.Column(sqlalchemy.String(length=50))
fullname = sqlalchemy.Column(sqlalchemy.String(length=50))
nickname = sqlalchemy.Column(sqlalchemy.String(length=50))
def __repr__(self):
return "<User(name='{0}', full name='{1}', nick name='{2}')>".format(
self.name, self.fullname, self.nickname)
# Create a session
Session = sqlalchemy.orm.sessionmaker()
Session.configure(bind=engine)
session = Session()
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)
The script having this code snippet was working till a while ago. I recently needed to import mysql.connector
in another script and performed pip install mysql-connector-python-rf
. Then, I have started getting this error with this script. I have looked at other threads discussing this error but not able to resolve the error in my case. For e.g., I added connect_args={'auth_plugin':'mysql_native_password'}
after reading this but still get the same error.