I am trying to connect to a MySQL server with python connector. I created a new user lcherukuri with the authentication plugin mysql_native_password.
But I got the error
mysql.connector.errors.NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported
Can someone help me?
import mysql.connector
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1',
database='test')
cnx.close()
Advertisement
Answer
Per Caching SHA-2 Pluggable Authentication
In MySQL 8.0,
caching_sha2_passwordis the default authentication plugin rather thanmysql_native_password.
You’re using mysql_native_password, which is no longer the default. Assuming you’re using the correct connector for your version you need to specify the auth_plugin argument when instantiating your connection object
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1', database='test',
auth_plugin='mysql_native_password')
From those same docs:
The
connect()method supports anauth_pluginargument that can be used to force use of a particular plugin. For example, if the server is configured to usesha256_passwordby default and you want to connect to an account that authenticates usingmysql_native_password, either connect using SSL or specifyauth_plugin='mysql_native_password'.
