Home >Database >Mysql Tutorial >How to Resolve 'Authentication plugin 'caching_sha2_password' is not supported' in MySQL Python Connector?

How to Resolve 'Authentication plugin 'caching_sha2_password' is not supported' in MySQL Python Connector?

DDD
DDDOriginal
2024-12-21 00:10:09330browse

How to Resolve

"Authentication plugin 'caching_sha2_password' is not supported: Resolved Through Auth_plugin Specification

When 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 arises when the authentication plugin defined for the user attempting to connect is different from the supported plugin for the MySQL server.

In the provided example, the error occurs because the lcherukuri user is configured with the mysql_native_password authentication plugin, while the MySQL server expects a supported authentication plugin.

To resolve this issue, modify the Python connector script by explicitly specifying the supported authentication plugin using the auth_plugin argument. In this case, the auth_plugin should be set to 'mysql_native_password' to match the user's authentication plugin.

Here's the corrected code:

import mysql.connector

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

By specifying the correct auth_plugin, you can ensure that the connection to the MySQL server is established using the supported authentication plugin, resolving the error.

The above is the detailed content of How to Resolve 'Authentication plugin 'caching_sha2_password' is not supported' in MySQL Python Connector?. 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