Software Development

How do I fix mysql.connector.errors.NotSupportedError for 'caching_sha2_password' in Python?

MA Asked by Marcus Thorne · 05-01-2026
0 upvotes 18,736 views 0 comments
The question

I am trying to connect my Python script to a fresh installation of MySQL 8.0, but I keep getting a "NotSupportedError" regarding the 'caching_sha2_password' authentication plugin. I am using the mysql-connector library, and it seems like my script doesn't recognize the default encryption method used by the newer MySQL server. Should I change the user's password type on the server, or is there a specific way to upgrade my Python driver to support this modern authentication method?

3 answers

0
KI
Answered on 06-01-2026

The error occurs because MySQL 8.0 changed the default authentication plugin to caching_sha2_password, while older versions of the mysql-connector library (or the unofficial mysql-connector-python) only support the legacy mysql_native_password. The best long-term solution in professional software development is to upgrade your library to the latest version using pip install --upgrade mysql-connector-python. If you are unable to upgrade your Python environment, you can alter the MySQL user to use the older method by running the SQL command: ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';. However, upgrading the driver is preferred as SHA2 offers significantly better security for enterprise data.

0
DE
Answered on 07-01-2026

If you decide to stick with the caching_sha2_password plugin for better security, do you also need to install the cryptography package in your Python environment for the handshake to work correctly?

CH 08-01-2026

Derek is spot on. For many Python MySQL drivers, the caching_sha2_password method requires the cryptography library to handle the RSA key exchange. Even if your driver is up to date, the connection might fail without it. I always recommend running pip install cryptography alongside your database drivers. In modern Data Science pipelines, ensuring your environment supports these encrypted handshakes is a standard security requirement, as it protects your database credentials from being intercepted during the initial connection phase.

0
SA
Answered on 10-01-2026

I had this same issue after moving to a Dockerized MySQL 8 instance. Changing the user plugin to mysql_native_password fixed it instantly, but I eventually just switched to PyMySQL which handles the new plugin much more smoothly.

MA 11-01-2026

I agree with Sarah; PyMySQL or mysqlclient are often more robust alternatives if the official connector keeps giving you trouble. Sometimes a simple library switch saves hours of configuration!

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session