MySQL error authentication plugin 'caching_sha2_password' is not supported in Python
Hello, I have created a project web with Python and MySQL.
I have written some lines of code as below to help me open to connect to MySql
My code:
import mysql.connector as sql
con = sql.connect(host="127.0.0.1", user="sa", passwd="my_pass", database="students")
if con.is_connected() == false
print("Cant not connect to My SQL")
con.close()
But when running that code I got an exception throw Authentication plugin 'caching_sha2_password' is not supported.
Anyone can explain to me why it throws and how can I solve it?
Thanks for any idea.
-
f0
fahmi zaki Nov 16 2021
You can add more
auth_plugin='mysql_native_password'
pram in the connection string as below:Replace this line code:
con = sql.connect(host="127.0.0.1", user="sa", passwd="my_pass", database="test")
To
conn = mysql.connector.connect(user='root', password='password', host='127.0.0.1',port=5000,database='test', auth_plugin='mysql_native_password')
I hope it works for you.
-
S0
Samuel Clemmons Nov 16 2021
Do you install
mysql-connector
?run
pip uninstall mysql-connector
and run
pip install mysql-connector-python
And finally, try to run again your code.
-
A0
Aa Nov 16 2021
I have been got same error before, and I tried to run
pip install mysql-connector-python
command and it worked for me.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.