Skip to content
Advertisement

MySQL error in Python – cannot connect to MySQL server

I have a question:

My input:

import mysql.connector
import mysql.connector

mydb = mysql.connector.connect(
    host = 'localhost',
    user = 'root',
    passwd = 'ananthjeahinowiamshowingmypasswordwitchisnotmypassword'
)
print(mydb)

And this is the output:

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

Advertisement

Answer

Install the Python MySQL driver:

Official document

Similar Stack Overflow question

Just make sure to install the correct connector based on your operating system, MySQL version and the Python version you use:

pip install mysql-connector-python
Advertisement