mysql 如何解决以下“不支持身份验证插件'caching_sha2_password'”错误?

1cklez4t  于 2024-01-05  发布在  Mysql
关注(0)|答案(1)|浏览(405)

当我运行以下代码片段时,我得到错误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

  1. import sqlalchemy
  2. from sqlalchemy.ext.declarative import declarative_base
  3. # Define the MySQL engine using MySQL Connector/Python
  4. engine = sqlalchemy.create_engine(
  5. 'mysql+mysqlconnector://pyuser:Py@pp4Demo@localhost:3306/sqlalchemy', connect_args={'auth_plugin':'mysql_native_password'}, echo=True)
  6. # Define and create the table
  7. Base = declarative_base()
  8. class User(Base):
  9. __tablename__ = 'user'
  10. id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
  11. name = sqlalchemy.Column(sqlalchemy.String(length=50))
  12. fullname = sqlalchemy.Column(sqlalchemy.String(length=50))
  13. nickname = sqlalchemy.Column(sqlalchemy.String(length=50))
  14. def __repr__(self):
  15. return "<User(name='{0}', full name='{1}', nick name='{2}')>".format(
  16. self.name, self.fullname, self.nickname)
  17. # Create a session
  18. Session = sqlalchemy.orm.sessionmaker()
  19. Session.configure(bind=engine)
  20. session = Session()
  21. Base.metadata.drop_all(bind=engine)
  22. Base.metadata.create_all(bind=engine)

字符串
有此代码片段的脚本一直工作到一段时间前.我最近需要在另一个脚本中import mysql.connector并执行pip install mysql-connector-python-rf .然后,我已经开始得到这个错误与此脚本.我已经看了其他线程讨论这个错误,但无法解决在我的情况下的错误.例如.,我添加connect_args={'auth_plugin':'mysql_native_password'}后阅读this,但仍然得到相同的错误.

3okqufwl

3okqufwl1#

我有同样的问题,然后发现这是因为我安装了错误的软件包
pip install mysql-connector-python
然后导入为import mysql.connector
有了这个命令,

相关问题