0

I was trying to connect MySQL with python via the following code.

import mysql.connector
mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="qwerty",
  auth_plugin="mysql_native_password"
)

print(mydb)

It gave me the following error:-

mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

My connector version is:-

C:\Users\samar>pip install mysql-connector-python
Requirement already satisfied: mysql-connector-python in c:\users\samar\anaconda3\lib\site-packages (8.0.21)

1 Answer 1

1
import pymysql

host="localhost"
user="root"
passwd="qwerty"
db="<give db name"

def dbConnectivity(host,user, passwd, db):
    try:
        db = pymysql.connect(host=host,
                             user=user,
                             passwd=passwd,
                             db=db)
        cursor = db.cursor()
        print("Great !!! Connected to MySQL Db")
        return cursor
    except pymysql.Error as e:
        print("Sorry !! The error in connecting is:" + str(e))
        return str(e)

dbConnectivity(host,user,passwd,db)
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't answer the question, he asks for connecting to a legacy database, for which his solution is nearer than this solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.