Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

(2059,“Authentication Plugin 'caching_sha2_password'”) when running server connected with MYSQL database on Django

I want to configure my django project in order to connect it with database in MYSQL I created with workbench 8.0,
and then I want to run the server by running

python manage.py runserver

from anaconda command prompt,
so that I can use the Django interface to visualize and alter data.
Please note that I don’t want to downgrade workbench 8.0.

These are the steps I have made:

From anaconda prompt:

pip install mysqlclient

In my project folder, in settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'schema_meta',
        'USER': 'root',
        'PASSWORD': '<mypassword>',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    },
}

Inside the directory of mysql server, I open cnf.ini and insert a the [client] section:

[client]
database=schema_meta
host=127.0.0.1
user=root
password=<mypassword>
port=3306
default-character-set = utf8

Then from anaconda prompt I run

Python manage.py runserver

And I obtain error

django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: Impossibile trovare il modulo specificato. ")

So I try to solve it by following this thread:
django.db.utils.operationalError: (2059,"Authentication Plugin 'caching_sha2_password'")

I open mysql workbench and I run this query:

delete from mysql.user
where user='root'
and host = '127.0.0.1';
flush privileges;
CREATE  USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '<mypassword>';

And then, in the my.ini file I change

default-authentication-plugin= caching_sha2_password

With

default-authentication-plugin=mysql_native_password

Finally from anaconda prompt:

python manage.py runserver

But again I get

django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: Impossibile trovare il modulo specificato. ")

Now, what’s wrong? Why it did not get the changes into the authentication method?

In order to check that there are no other errors, from mysql workbench, from first “home” view, I right click on my database, I open “edit connection”, I click on “test connection”, and the software says that the connection is successfull.

mysql workbench saying connection successfully established

Moreover, I wanted to check if the problem was in my Django settings. So from anaconda prompt I run

pip install pymysql

Then in the project folders I created a “connect_to_mysql.py” script, with the following code inside:

import pymysql.cursors
mydb = pymysql.connect(host='127.0.0.1',
                             user='root',
                             password='<mypassword>',
                             db='schema_meta',
                             charset='utf8mb4',
                             cursorclass=pymysql.cursors.DictCursor)
print(mydb)

and this seems to work fine, since when I run

connect_to_mysql.py 

from anaconda, I get

pymysql.connections.Connection object at 0x000002013F2851D0

That I guess it means “connection successfully established”.
And just to be sure that the problem is into mysql (mysql connector I guess), I create a file “connect_to_mysql_2.py” with this code inside:

import mysql.connector
mydb = mysql.connector.connect(user='root', password='<mypassword>',
                             host='127.0.0.1', database='meta_schema')
print(mydb)

And when I run it from anaconda, again I get

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

That means that I fixed nothing by working on mysql workbench and in my.ini file.

How can I get my Django connected with my mysql database and my server running?

Is there a way to establish the server connector using pymysql connector instead that mysql connector?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is probably not a problem in your python code, but in the python connector. The caching_sha2_password plugin is now the default auth plugin and clients have to support it in order to connect. So, the best solution is to update your python connector. An alternative way is to disable this plugin, but that's something I don't recommend as it lowers your server's security.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...