[Python] mysql.connector.errors.NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported

Python + MySQL 8.0 資料庫,可是報了以上錯誤。

原因:

在MySQL 8.0以後,預設認證方式為:caching_sha2_password而不是mysql_native_password。

解法:

多傳入一個參數auth_plugin即可:

範例:

import mysql.connector

db = mysql.connector.connect(
host=’host’,
user=’user’,
passwd=’password’,
auth_plugin=’mysql_native_password’
)

資料來源:
https://stackoverflow.com/questions/50557234/authentication-plugin-caching-sha2-password-is-not-supported

In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_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 an auth_plugin argument that can be used to force use of a particular plugin. For example, if the server is configured to use sha256_password by default and you want to connect to an account that authenticates using mysql_native_password, either connect using SSL or specify auth_plugin='mysql_native_password'.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *