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
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.
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")
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.
Samuel Clemmons Nov 16 2021
Do you install
pip uninstall mysql-connector
pip install mysql-connector-python
And finally, try to run again your code.
Aa Nov 16 2021
I have been got same error before, and I tried to run
pip install mysql-connector-pythoncommand and it worked for me.