0

I am trying to use Python 3.7 to connect to various MySQL and MariaDB databases using ver 8.0.18 of the mysql.connector (installed via pip as the mysql-connector-python package).

In this particular instance, I am trying to connect to a MariaDB 5.5.52 instance, but seem to be having the same problem on other systems.

If I attempt to connect thus:

cnx = mysql.connector.connect(user=c['user'], password=c['password'], host=c['host'], database=c['database'])

I get

mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user '<user name>'@'<ip address>' (using password: YES)

The mysterious thing is that I can use a client application (JetBrains DataGrip) to connect from the same PC to the databases in question without any problems, so I am confident that the credentials are valid and there aren't any network or similar problems preventing the connection (i.e. port 3306 is open).

The only common factor I can find seems to be the mysql.connector. I've checked the manual and it looks like the syntax is correct.

UPDATE Following @makozaki's advice to use a different connector (pymysql) the code works. So it would definitely appear to be the mysql.connector that's the problem. I might try rolling it back to a previous version to see if that fixes it (unless anyone out there knows of a workaround).

3
  • If you suspect that it might be connector issue then how about you test other connectors first, e.g. pymysql, if problem reappears then maybe you misspelled your credentials or there are multiple access settings for your user and one of them doesn't have proper rights. Commented Jan 2, 2020 at 11:09
  • @makozaki Doh! Why didn't I think of that! If I use the pymysql connector then it works fine. Most odd. Thanks for your advice. Commented Jan 2, 2020 at 11:17
  • 1
    I would still check database user permissions. There might be multiple permissions for the user you are trying to connect with and one of them might not grant proper access, e.g. ’user@localhost' vs '[email protected]'. I checked the previous connector and it worked fine for me. Commented Jan 3, 2020 at 8:09

2 Answers 2

1

I was able to fix this same error message for mysql.connector by adding in the additional parameter 'tls_versions':

cnx = mysql.connector.connect(user=c['user'], password=c['password'], host=c['host'], database=c['database'], 'tls_versions'=['TLSv1.1', 'TLSv1.2'])

This works because, as of the update 8.0.18, you can now specify the TLS version if it doesn't match the version of your database.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this fixed perfectly my issue: mysql.connector.errors.InterfaceError: Failed parsing handshake; end byte not present in buffer
0

So far as I can tell, this turned out to be something to do with character encoding. The password I was using had some strange characters in it, including a British pound sign and an accented foreign (European) character.

For reasons I don't yet understand, the DataGrip client passed these without any problem, yet the mysql.connector somehow nobbled them.I suspect that this is something to do with encoding, although everything is set (or defaults to) utf-8.

I've changed the password(s) to ones encoded in base64 and the problem appears to have been solved, although I am frustrated that I haven't got to the bottom of why it occurred in the first place.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.