Python连接MySQL数据库报错OperationalError(2059)求助
解决Python中MySQLdb连接报错(2059, )的问题
我之前也碰到过这个一模一样的问题,折腾了好一会儿才找到根源,分享给你:
问题重现
在Python Shell中执行以下MySQL连接代码:
import MySQLdb Con = MySQLdb.Connect(user='testuser', password='password', db='test')
直接抛出了无描述信息的报错:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Nickey\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\__init__.py", line 86, in Connect return Connection(*args, **kwargs) File "C:\Users\Nickey\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py", line 204, in __init__ super(Connection, self).__init__(*args, **kwargs2) _mysql_exceptions.OperationalError: (2059, <NULL>)
这个报错连个提示信息都没有,刚开始真的有点摸不着头脑。
问题原因与解决方法
后来排查清楚了,这个错误和MySQL的新身份验证插件以及它的「Strong Password Encryption for Authentication」特性直接相关。旧版本的MySQLdb库不支持MySQL默认的caching_sha2_password验证方式,所以只需要把MySQL Server的身份验证配置切换为旧的old_password_plugin(也就是Legacy Authentication Method),重新尝试连接就能解决问题了。
内容的提问来源于stack exchange,提问作者Nickey Production
相关产品推荐
相关产品推荐

