PyMySQL Access Denied using password (no) but using password

2024/9/19 14:21:45

Headscratcher here for me.

I am attempting to connect to a database on my local MySQL 8.0.11.0 install from Python.

Here's the code I'm using :

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

Python is returning the following :

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 Connectreturn 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 connectself._request_authentication()File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1203, in _request_authenticationauth_packet = self._read_packet()File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1059, in _read_packetpacket.check_error()File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 384, in check_errorerr.raise_mysql_exception(self._data)File "C:\Program Files\Python36\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exceptionraise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

I have confirmed that I have access to the database when logging in through MySQL Workbench. The weird thing is that Python is telling me "using password: NO" even though I'm sending a password.

I've tried changing passwd to "password" in the script and creating a new user with the appropriate privileges. Neither has worked.

Not sure what to check next.

EDIT: Here are grants for root:

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

EDIT 2: Added debug lines to connect and _request_authentication in connections.py.

Here's the latest:

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= placeholderTraceback (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 Connectreturn 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 connectself._request_authentication()File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1218, in _request_authenticationauth_packet = self._read_packet()File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1067, in _read_packetpacket.check_error()File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 384, in check_errorerr.raise_mysql_exception(self._data)File "C:\Program Files\Python36\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exceptionraise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

EDIT 3: Enabled logging. No surprises in the log, but here's what the latest attempt generated:

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)

EDIT 4: Found the problem. I added some debug statements as follows:

    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)

The problem is this IF block fails... program flow isn't getting to the "authresp" statement. When a peer of mine runs this same program, his passwords prints in the console.

So, now I just need to figure out why I'm not going down this branch.

Answer

Resolved the issue after downgrading MySQL from 8.0.11.0 to 5.7.22.

In addition to what I listed in my original question, I also tried the following:

  • Installed lower version of PyMySQL (0.8.1 to 0.8.0 in my case)
  • Completely removed both versions of PyMySQL and installed v0.8.0
  • Removed MySQL 8.0 and reinstalled

When none of the above worked, I downgraded MySQL to v5.7, which is what one of my peers is using. That resolved the error.

https://en.xdnf.cn/q/72738.html

Related Q&A

Trouble importing Python modules on Ninja IDE

I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly …

UTF-8 error with Python and gettext

I use UTF-8 in my editor, so all strings displayed here are UTF-8 in file.I have a python script like this:# -*- coding: utf-8 -*- ... parser = optparse.OptionParser(description=_(automates the dice ro…

Add build information in Jenkins using REST

Does anyone know how to add build information to an existing Jenkins build? What Im trying to do is replace the #1 build number with the actual full version number that the build represents. I can do …

Combining element-wise and matrix multiplication with multi-dimensional arrays in NumPy

I have two multidimensional NumPy arrays, A and B, with A.shape = (K, d, N) and B.shape = (K, N, d). I would like to perform an element-wise operation over axis 0 (K), with that operation being matrix …

Target array shape different to expected output using Tensorflow

Im trying to make a CNN (still a beginner). When trying to fit the model I am getting this error:ValueError: A target array with shape (10000, 10) was passed for output of shape (None, 6, 6, 10) while …

Using openpyxl to refresh pivot tables in Excle

I have a file that has several tabs that have pivot tables that are based on one data tab. I am able to write the data to the data tab without issue, but I cant figure out how to get all of the tabs wi…

python: is there a library function for chunking an input stream?

I want to chunk an input stream for batch processing. Given an input list or generator,x_in = [1, 2, 3, 4, 5, 6 ...]I want a function that will return chunks of that input. Say, if chunk_size=4, then,x…

jinja2: How to make it fail Silently like djangotemplate

Well i dont find the answer Im sure that its very simple, but i just dont find out how to make it work like Django when it doesnt find a variablei tried to use Undefined and create my own undefined but…

ImportError when from transformers import BertTokenizer

My code is: import torch from transformers import BertTokenizer from IPython.display import clear_outputI got error in line from transformers import BertTokenizer: ImportError: /lib/x86_64-linux-gnu/li…

How to get feature names of shap_values from TreeExplainer?

I am doing a shap tutorial, and attempting to get the shap values for each person in a dataset from sklearn.model_selection import train_test_split import xgboost import shap import numpy as np import …