Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code 2006 raised for invalid password instead of 1045 #316

Closed
bb-st opened this issue Dec 14, 2018 · 0 comments
Closed

Error code 2006 raised for invalid password instead of 1045 #316

bb-st opened this issue Dec 14, 2018 · 0 comments

Comments

@bb-st
Copy link

bb-st commented Dec 14, 2018

When connecting to MySQL with an invalid password, up until version 1.3.13 the following exception is raised by mysqlclient-python:

_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'127.0.0.1' (using password: YES)")

with version 1.3.14 and 1.4.0rc1 the following exception is raised instead:

_mysql_exceptions.OperationalError: (2006, "Access denied for user 'root'@'127.0.0.1' (using password: YES)")

Note the MySQL error code is now 2006 (normally representing "server has gone away") instead of code 1045 (Access denied).

This can easily be seen with the following python code:

import MySQLdb
MySQLdb.connect(host="127.0.0.1",user="root",passwd="wrong")

Tested on Ubuntu 16.04 with Python 2.7.12 and MySQL 5.7.24

Example session

root@myhost:/tmp# cat my.py
import MySQLdb
MySQLdb.connect(host="127.0.0.1",user="root",passwd="wrong")

root@myhost:/tmp# pip list | grep mysql
mysqlclient                   1.3.14

root@myhost:/tmp# mysql -u root --password=wrong -h 127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

root@myhost:/tmp# python my.py
Traceback (most recent call last):
  File "my.py", line 2, in <module>
    MySQLdb.connect(host="127.0.0.1",user="root",passwd="wrong")
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 85, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 208, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2006, "Access denied for user 'root'@'127.0.0.1' (using password: YES)")

root@myhost:/tmp# pip uninstall mysqlclient
Uninstalling mysqlclient-1.3.14:
<snip>
root@myhost:/tmp# pip install mysqlclient==1.3.13
<snip>
Successfully installed mysqlclient-1.3.13

root@myhost:/tmp# mysql -u root --password=wrong -h 127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

root@myhost:/tmp# python my.py
Traceback (most recent call last):
  File "my.py", line 2, in <module>
    MySQLdb.connect(host="127.0.0.1",user="root",passwd="wrong")
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 85, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'127.0.0.1' (using password: YES)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant