【问题标题】:(Python) MySQL database Authentication trouble(Python) MySQL数据库认证麻烦
【发布时间】:2018-06-25 19:00:00
【问题描述】:

我正在尝试运行以下代码以将 symbols 变量的组件添加到名为 securities_master 的数据库中。我之前发布了这个问题并修复了大量错误,但是,我仍然收到以下错误:

Traceback (most recent call last):

 File "C:/Users/Nathan/.PyCharmCE2018.1/config/scratches/scratch.py", line 28, in <module>
insert_btc_symbols(symbols)
 File "C:/Users/Nathan/.PyCharmCE2018.1/config/scratches/scratch.py", line 15, in insert_btc_symbols
con = MySQLdb.connect(host=db_host,user=db_user,db=db_name) #,passwd=db_pass
 File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
 File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1251, 'Client does not support authentication protocol requested by server; consider upgrading MySQL client')

Process finished with exit code 1

我尝试通过没有密码的用户和 root 用户以及密码的公钥进行连接,但均无济于事。以下是我正在执行的代码:

import datetime
import MySQLdb
from math import ceil

def obtain_btc():
    now = datetime.datetime.utcnow()
    symbols = ['BTC', 'Crypto', 'Bitcoin', 'No Sector', 'USD', now, now]
    return symbols

def insert_btc_symbols(symbols):
    db_host = 'localhost'
    db_user = 'natrob2'
    #db_pass = ''
    db_name = 'securities_master'
    con = MySQLdb.connect(host=db_host,user=db_user,db=db_name) #,passwd=db_pass
    column_str = "ticker, instrument, name, sector, currency, created_date, last_updated_date"
    insert_str = (("%s, ")*7)[:2]
    final_str = ("INSERT INTO symbol (%s) VALUES (%s)" % (column_str,insert_str))
    print (final_str,len(symbols))

    with con:
        cur = con.cursor()
        for i in range(0,int(ceil(len(symbols)/100.0))):
            cur.executemany(final_str,symbols[i*100:(i+1)*100-1])

if __name__ == "__main__":
    symbols = obtain_btc()
    insert_btc_symbols(symbols)

【问题讨论】:

    标签: python mysql sql database connection


    【解决方案1】:

    客户端端点身份验证协议似乎与服务器没有内联。 你能试试下面提到的步骤吗? https://dev.mysql.com/doc/refman/5.5/en/old-client.html

    请查看相关问题 client does not support authentication protocol requested by server consider upgrading mysql client

    【讨论】:

    • 我尝试了您的建议,即使用 OLD_PASSWORD() 函数将我的密码重置为兼容的密码,但遇到了一个语法错误,告诉我检查手册中的语法是否适合我的版本.原来 OLD_PASSWORD() 已为 MySQL 8.0 删除……。 dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-11.html
    • 我最终通过使用以下命令使其工作:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password' 您的回答帮助我找到了正确的方法,所以谢谢。
    • 嘿@Mikey Mike 你能解释一下你在哪里输入了 ALTER USER... 查询来解决你的问题,是在 mysql 提示符下,我试着在那里输入,但发生的只是箭头提示 ->,我仍然有 OperationalError
    猜你喜欢
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多