9

i'm trying to get my python program to insert data into MySQL and i followed a guide however i keep getting the error below.

"Authentication plugin '{0}' is not supported".format(plugin_name)) mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported"

have i missed a setting in mysql server or does python not support this yet?

I think i can just change the password type but mysql doesn't want to let me for some reason all users with caching_sha2_password can't be changed and when i create a new user and select SHA256 Password I get the error creating account @% the password hash doesn't have the expected format. check if the correct password algorithm is being used with the PASSWORD() function.

#!/user
# -*- coding: utf-8 -*-

from __future__ import print_function
import urllib.request
import numpy as np
import mysql.connector as mysql

from datetime import date, datetime, timedelta



cnx = mysql.connect(user='root', password='password', database='powergrid')

cursor = cnx.cursor()

tomorrow = datetime.now().date() + timedelta(days=1)

idfueltype= cursor.lastrowid

add_fueltype = ("INSERT INTO fueltype"
                "(idfueltype, fueltypecol, demand)"
               "VALUES(%s, %s, %s)")

fueltype_data = (idfueltype, 'coal', 10000)

cursor.execute(add_fueltype, fueltype_data)

cnx.commit()

cursor.close()
cnx.close()
adam Wadsworth
  • 774
  • 1
  • 8
  • 26

8 Answers8

28

I managed to fix this. In the end I was using a version of python in Anaconda which just wouldn't install version 8.0.11 of the python connector, I managed to get 8.0.11 installed on my vanilla python 3.6.5 using windows PowerShell (in admin privileges) and using pip install MySQL-connector-python (I think I also had to update pip from 9 to 10.

adam Wadsworth
  • 774
  • 1
  • 8
  • 26
10

Installs the drive for python3.

python3 -m pip install mysql-connector-python

Installs the drive for the default python preinstalled on your system by the manufacturer.

python -m pip install mysql-connector-python
Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
DKMDebugin
  • 551
  • 7
  • 16
  • 1
    A little nitpick, running these commands in the root context is plain wrong and might turn your Linux into a pumkin. Never run pip in root context, there are apt/yum/... whatever tools which manage the system packages, pip shall be used in the user context only. – mestia Jul 14 '22 at 11:23
6

I had the same problem

"Authentication plugin '{0}' is not supported".format(plugin_name)) mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported"

This happens because your Python connector does not support the authentication plugin caching_sha2_password and you need to update it. I fixed it by installing the correct Python connector from MySQL official site. Be sure to download the correct connector based on your operating system, MySQL version and the Python version you use.

3

Seems this package works for me: sudo pip install MySQL-connector-python

Allen211
  • 69
  • 6
2

I was getting the exact same issue and tried to update the mysql-connector module with pip as suggested in the accepted answer, however that did not help. I realized that the problem might be related to my Anaconda environment, hence I tried using conda for updating my mysql-connector-python module.

Finally I resolved this issue with the following command:

conda install -c anaconda mysql-connector-python

This seems to do what pip could not do, at least in my case. The link of the conda package is: https://anaconda.org/anaconda/mysql-connector-python

reincore
  • 345
  • 5
  • 11
2

Got the same issue just now, and tried all the answers above (none worked).

Per MySQL 8 documentation, easiest way to fix this is to add the following to your MySQL d file -> restart MySQL server. This worked for me!

If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (mysql_native_password). For example, use these lines in the server option file:

[mysqld]
#add the following file to your MySQLd file
    default_authentication_plugin=mysql_native_password
FlyingZebra1
  • 1,285
  • 1
  • 18
  • 28
1

MySQL 8.0 made caching_sha2_password the default authentication for new accounts, which requires updated connectors to be able to use it. Alternatively, you can change the account to use the native auth method (but that is less secure).

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
0

Personally, I’m a fan of the pymysql package.
Added bonus: the implementation is based on PEP 249, and it is purely Python!

Please note:

Most public APIs are compatible with mysqlclient and MySQLdb.
PyMySQL doesn’t support low level APIs _mysql provides like data_seek, store_result, and use_result. You should use high level APIs defined in PEP 249. But some APIs like autocommit and ping are supported because PEP 249 doesn’t cover their usecase.

Lior Pollak
  • 3,362
  • 5
  • 27
  • 48