Samar Pratap Singh
Samar Pratap Singh

Reputation: 531

How to change the authentication configuration of mysql connector to python?

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)

Upvotes: 0

Views: 544

Answers (1)

Kiran Kumar
Kiran Kumar

Reputation: 11

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)

Upvotes: 1

Related Questions