MySQL error authentication plugin 'caching_sha2_password' is not supported in Python

Dung Do Tien Nov 16 2021 135

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.

MySQL error 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.

Have 3 answer(s) found.
  • f

    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.

  • S

    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.

  • A

    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.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close