python中mysql连接错误NotSupportedError)Authentication plugin ‘caching_sha2_password‘ is not supported

转载:https://www.cnblogs.com/heymonkey/p/11715295.html
mysql连接错误:mysql.connector.errors.NotSupportedError) Authentication plugin ‘caching_sha2_password’ is not supported

def mysqlexecute(sql):
    # 获取当前文件路径
    filePath = os.path.dirname(__file__)
    # 获取当前文件的
    fileNamePath = os.path.split(os.path.realpath(__file__))[0]
    # 获取配置文件的路径
    yamlPath = os.path.join(fileNamePath, 'mysqltest.yml')
    filemysql =  open(yamlPath, 'r', encoding='utf-8')
    f=filemysql.read()
    con=yaml.load(f)
    list=con.get('mysql.connector.connect')
    print(list)
    # conn = con.get('mysql.connector.connect')
    conn=mysql.connector.connect(
         host=list.get('host')
         ,user =list.get('user')  # 用户名
         ,passwd = list.get('passwd')  # 密码
         ,port =list.get('port')  # 端口,默认为3306
         ,db = list.get('db')  # 数据库名称
         ,charset = list.get('charset')  # 字符编码
    )
      print(conn)
    cur=conn.cursor()
    cur.execute(sql)
    date=cur.fetchall()
    print(date)
    # for i in date[i]:
    #     print(i)
    cur.close()
    conn.close()
    return date

运行时报错:错误描述
mysql.connector.errors.NotSupportedError) Authentication plugin ‘caching_sha2_password’ is not supported
发现是:

 conn=mysql.connector.connect(
         host=list.get('host')
         ,user =list.get('user')  # 用户名
         ,passwd = list.get('passwd')  # 密码
         ,port =list.get('port')  # 端口,默认为3306
         ,db = list.get('db')  # 数据库名称
         ,charset = list.get('charset')  # 字符编码
    )

这里报错:
排查后发现是缺少MySQL-connector-python
安装
pip install MySQL-connector-python
就正常访问

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值