Home >Database >Mysql Tutorial >Why Does My Python MySQL Connection Fail with 'Authentication plugin 'caching_sha2_password' is not supported'?

Why Does My Python MySQL Connection Fail with 'Authentication plugin 'caching_sha2_password' is not supported'?

Linda Hamilton
Linda HamiltonOriginal
2024-12-05 15:29:10311browse

Why Does My Python MySQL Connection Fail with

Unable to Connect to MySQL Due to Unsupported Authentication Plugin

While attempting to establish a connection to a MySQL server using the Python connector, you may encounter the error "Authentication plugin 'caching_sha2_password' is not supported." This error can arise when the specified authentication plugin is not supported by the client or server.

Root Cause:

In this particular instance, the root cause of the error is a mismatch between the authentication plugin used to create the user and the plugin supported by the Python connector. By default, the connector supports the "mysql_native_password" authentication plugin, whereas the user "lcherukuri" was created using the "caching_sha2_password" plugin.

Solution:

To resolve this issue, ensure that the authentication plugin used to create the user matches the plugin supported by the connector. In this case, you can specify the "auth_plugin" parameter when establishing the connection, explicitly setting it to "mysql_native_password":

import mysql.connector

cnx = mysql.connector.connect(user='lcherukuri', password='password',
                              auth_plugin='mysql_native_password',
                              host='127.0.0.1',
                              database='test')
cnx.close()

Additional Notes:

  • Confirm that you are using the correct Python connector package (e.g., "mysql-connector-python") and not an outdated or incompatible version (e.g., "mysql-connector").
  • If you encounter any other related errors, refer to the MySQL documentation for additional troubleshooting steps.

The above is the detailed content of Why Does My Python MySQL Connection Fail with 'Authentication plugin 'caching_sha2_password' is not supported'?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn