pymysql访问被拒绝“使用密码(no)”,但使用密码

pn9klfpd  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(388)

我的头巾。
我正在尝试从python连接到本地mysql 8.0.11.0安装上的数据库。
下面是我使用的代码:

conn = pymysql.connect(host='localhost', port=3306, user='root', password='placeholder', db='CustomerInfo')

python正在返回以下内容:

Traceback (most recent call last):
  File "D:\Python\FileCheck.py", line 38, in <module>
    conn = pymysql.connect(host='localhost', port=3306, user='root', password='placeholder', db='CustomerInfo')
  File "C:\Program Files\Python36\lib\site-packages\pymysql\__init__.py", line 90, in Connect
    return Connection(*args,**kwargs)
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 704, in __init__
    self.connect()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 974, in connect
    self._request_authentication()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1203, in _request_authentication
    auth_packet = self._read_packet()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1059, in _read_packet
    packet.check_error()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "C:\Program Files\Python36\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

我已经确认在通过mysql工作台登录时可以访问数据库。奇怪的是Python告诉我 "using password: NO" 即使我在发送密码。
我试过换衣服 passwd"password" 并创建具有相应权限的新用户。两者都不起作用。
不知道下一步要检查什么。
编辑:下面是根用户的授权:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION
GRANT BACKUP_ADMIN,BINLOG_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,GROUP_REPLICATION_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SET_USER_ID,SYSTEM_VARIABLES_ADMIN,XA_RECOVER_ADMIN ON *....
GRANT ALL PRIVILEGES ON `customerinfo`.* TO `root`@`localhost` WITH GRANT OPTION
GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

编辑2:在connections.py中添加调试行以连接和\u请求\u身份验证。
以下是最新消息:

C:\Users\Paul Miller>python.exe D:\Python\FileCheck.py

**DEBUG 1**

connect, line 973
host= localhost
user= root
password= placeholder

**DEBUG 2**

_request_authentication line 1172
user= root
password= placeholder

Traceback (most recent call last):
  File "D:\Python\FileCheck.py", line 38, in <module>
    conn = pymysql.connect(host='localhost', port=3306, user='root', password='placeholder', db='CustomerInfo')
  File "C:\Program Files\Python36\lib\site-packages\pymysql\__init__.py", line 90, in Connect
    return Connection(*args,**kwargs)
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 704, in __init__
    self.connect()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 982, in connect
    self._request_authentication()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1218, in _request_authentication
    auth_packet = self._read_packet()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1067, in _read_packet
    packet.check_error()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "C:\Program Files\Python36\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

编辑3:启用日志记录。日志中没有意外,但最新的尝试产生了以下结果:

2018-05-15T10:27:15.197445Z    43 Connect   root@localhost on CustomerInfo using TCP/IP
2018-05-15T10:27:15.197540Z    43 Connect   Access denied for user 'root'@'localhost' (using password: NO)

编辑4:发现问题。我添加了一些调试语句,如下所示:

if self._auth_plugin_name in ('', 'mysql_native_password'):
        print("**DEBUG 3**")
        print(self.password)
        print("\n")
        authresp = _scramble(self.password.encode('latin1'), self.salt)

问题是如果块失败。。。程序流无法访问“authrep”语句。当我的一个同伴运行同一个程序时,他的密码会打印在控制台上。
所以,现在我只想弄明白我为什么不去这家分店。

h7wcgrx3

h7wcgrx31#

解决了mysql从8.0.11.0降级到5.7.22后的问题。
除了我在原始问题中列出的内容外,我还尝试了以下方法:
安装了pymysql的较低版本(在我的例子中是0.8.1到0.8.0)
完全删除了pymysql的两个版本并安装了v0.8.0
已删除mysql 8.0并重新安装
当以上这些都不起作用时,我将mysql降级到v5.7,这是我的一个同行正在使用的版本。解决了错误。

i5desfxk

i5desfxk2#

真奇怪。我会在虚拟环境中安装pymysql,然后在此函数中删除一些调试行:
https://github.com/pymysql/pymysql/blob/master/pymysql/connections.py#l940
这应该说明它实际用于连接的变量是什么,并使错误明显。

相关问题