Python mysql 不支持缓存 sha2 密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50243506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
caching sha2 password is not supported mysql
提问by adam Wadsworth
i'm trying to get my python program to insert data into MySQL and i followed a guide however i keep getting the error below.
我正在尝试让我的 python 程序将数据插入到 MySQL 中,我遵循了一个指南,但是我不断收到以下错误。
"Authentication plugin '{0}' is not supported".format(plugin_name)) mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported"
“不支持认证插件‘{0}’”.format(plugin_name)) mysql.connector.errors.NotSupportedError:不支持认证插件‘caching_sha2_password’”
have i missed a setting in mysql server or does python not support this yet?
我错过了 mysql 服务器中的设置还是 python 不支持这个?
I think i can just change the password type but mysql doesn't want to let me for some reason all users with caching_sha2_password can't be changed and when i create a new user and select SHA256 Password I get the error creating account @% the password hash doesn't have the expected format. check if the correct password algorithm is being used with the PASSWORD() function.
我想我可以只更改密码类型,但 mysql 出于某种原因不想让我所有具有 caching_sha2_password 的用户都无法更改,当我创建一个新用户并选择 SHA256 密码时,我收到错误创建帐户 @% the密码哈希没有预期的格式。检查 PASSWORD() 函数是否使用了正确的密码算法。
#!/user
# -*- coding: utf-8 -*-
from __future__ import print_function
import urllib.request
import numpy as np
import mysql.connector as mysql
from datetime import date, datetime, timedelta
cnx = mysql.connect(user='root', password='password', database='powergrid')
cursor = cnx.cursor()
tomorrow = datetime.now().date() + timedelta(days=1)
idfueltype= cursor.lastrowid
add_fueltype = ("INSERT INTO fueltype"
"(idfueltype, fueltypecol, demand)"
"VALUES(%s, %s, %s)")
fueltype_data = (idfueltype, 'coal', 10000)
cursor.execute(add_fueltype, fueltype_data)
cnx.commit()
cursor.close()
cnx.close()
回答by adam Wadsworth
I managed to fix this. In the end I was using a version of python in Anaconda which just wouldn't install version 8.0.11 of the python connector, I managed to get 8.0.11 installed on my vanilla python 3.6.5 using windows PowerShell (in admin privileges) and using pip install MySQL-connector-python
(I think I also had to update pip from 9 to 10.
我设法解决了这个问题。最后,我在 Anaconda 中使用了一个 python 版本,它不会安装 python 连接器的 8.0.11 版本,我设法使用 Windows PowerShell(以管理员权限)在我的 vanilla python 3.6.5 上安装了 8.0.11并使用pip install MySQL-connector-python
(我想我还必须将 pip 从 9 更新到 10。
回答by DKMDebugin
Installs the drive for python3.
安装 python3 的驱动器。
python3 -m pip install mysql-connector-python
python3 -m pip install mysql-connector-python
Installs the drive for the default python preinstalled on your system by the manufacturer.
为制造商预装在您的系统上的默认 python 安装驱动器。
python -m pip install mysql-connector-python
回答by Giuseppe Marcucci
I had the same problem
我有同样的问题
"Authentication plugin '{0}' is not supported".format(plugin_name)) mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported"
“不支持认证插件‘{0}’”.format(plugin_name)) mysql.connector.errors.NotSupportedError:不支持认证插件‘caching_sha2_password’”
This happens because your Python connectordoes not support the authentication plugin caching_sha2_password
and you need to update it. I fixed it by installing the correct Python connector from MySQL official site. Be sure to download the correct connector based on your operating system, MySQL version and the Python version you use.
发生这种情况是因为您的 Python连接器不支持身份验证插件caching_sha2_password
,您需要更新它。我通过从MySQL 官方网站安装正确的 Python 连接器来修复它。请务必根据您的操作系统、MySQL 版本和您使用的 Python 版本下载正确的连接器。
回答by Allen211
Seems this package works for me: sudo pip install MySQL-connector-python
似乎这个包对我有用:sudo pip install MySQL-connector-python
回答by reincore
I was getting the exact same issue and tried to update the mysql-connector module with pip as suggested in the accepted answer, however that did not help. I realized that the problem might be related to my Anaconda environment, hence I tried using condafor updating my mysql-connector-python module.
我遇到了完全相同的问题,并尝试按照已接受的答案中的建议使用 pip 更新 mysql-connector 模块,但这并没有帮助。我意识到问题可能与我的 Anaconda 环境有关,因此我尝试使用conda来更新我的 mysql-connector-python 模块。
Finally I resolved this issue with the following command:
最后我用以下命令解决了这个问题:
conda install -c anaconda mysql-connector-python
This seems to do what pip could not do, at least in my case. The link of the conda package is: https://anaconda.org/anaconda/mysql-connector-python
这似乎可以做 pip 不能做的事情,至少在我的情况下是这样。conda 包的链接是:https://anaconda.org/anaconda/mysql-connector-python
回答by FlyingZebra1
Got the same issue just now, and tried all the answers above (none worked).
刚刚遇到同样的问题,并尝试了上述所有答案(均无效)。
Per MySQL 8 documentation, easiest way to fix this is to add the following to your MySQL d file -> restart MySQL server. This worked for me!
根据MySQL 8 文档,解决此问题的最简单方法是将以下内容添加到 MySQL d 文件 -> 重新启动 MySQL 服务器。这对我有用!
If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (mysql_native_password). For example, use these lines in the server option file:
如果您的 MySQL 安装必须为 8.0 之前的客户端提供服务,并且您在升级到 MySQL 8.0 或更高版本后遇到兼容性问题,那么解决这些问题并恢复 8.0 之前的兼容性的最简单方法是重新配置服务器以恢复到以前的默认身份验证插件( mysql_native_password)。例如,在服务器选项文件中使用这些行:
[mysqld]
#add the following file to your MySQLd file
default_authentication_plugin=mysql_native_password
回答by Mike Lischke
MySQL 8.0 made caching_sha2_password
the default authentication for new accounts, which requires updated connectors to be able to use it. Alternatively, you can change the account to use the native auth method (but that is less secure).
MySQL 8.0caching_sha2_password
为新帐户设置了默认身份验证,这需要更新的连接器才能使用它。或者,您可以更改帐户以使用本机身份验证方法(但安全性较低)。