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’
)
In MySQL 8.0,
caching_sha2_password
is 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_plugin
argument that can be used to force use of a particular plugin. For example, if the server is configured to usesha256_password
by default and you want to connect to an account that authenticates usingmysql_native_password
, either connect using SSL or specifyauth_plugin='mysql_native_password'
.