mysql数据库问题无法连接python

eit6fx6z  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(389)

这个问题在这里已经有答案了

不支持身份验证插件“caching\u sha2\u password”(22个答案)
10个月前关门了。
我试图将我的数据库连接到python代码,但总是出现错误

import mysql.connector

db = mysql.connector.connect(
    host="localhost",
    user="*****",
    passwd="*******",
    )

mycursor = db.cursor()

mycursor.execute("CREATE DATABASE testdatabase")

错误显示:

Traceback (most recent call last):
  File , line 3, in <module>
    db = mysql.connector.connect(
  File Programs\Python\Python38-32\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
    return MySQLConnection(*args,**kwargs)
  File "Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
    self.connect(**kwargs)
  File Programs\Python\Python38-32\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
    self._open_connection()
  \Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 208, in _open_connection
    self._do_auth(self._user, self._password,
  File "Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 137, in _do_auth
    packet = self._protocol.make_auth(
  File Programs\Python\Python38-32\lib\site-packages\mysql\connector\protocol.py", line 99, in make_auth
    packet += self._auth_response(client_flags, username, password,
  File Programs\Python\Python38-32\lib\site-packages\mysql\connector\protocol.py", line 58, in _auth_response
    auth = get_auth_plugin(auth_plugin)(
  File Programs\Python\Python38-32\lib\site-packages\mysql\connector\authentication.py", line 190, in get_auth_plugin
    raise errors.NotSupportedError(
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
[Finished in 0.2s]
uqcuzwp8

uqcuzwp81#

答案是不用安装 pip install mysql.connector 安装mysql.connector-python pip install mysql.connector-python

相关问题