(Python)MySQL数据库身份验证问题
我试图运行下面的代码,将symbols变量的组件添加到名为securities_master的数据库中。我之前发布了此问题,并修复了大量错误,但我仍然收到以下错误:(Python)MySQL数据库身份验证问题,python,mysql,sql,database,connection,Python,Mysql,Sql,Database,Connection,我试图运行下面的代码,将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
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
客户端端点身份验证协议似乎没有与服务器内联。 你能试试下面提到的步骤吗? 请看相关问题
我曾尝试过您的建议,即使用OLD_PASSWORD()函数将我的密码重置为一个兼容的密码,但遇到了一个语法错误,告诉我检查我版本手册中的语法。原来MySQL 8.0的旧密码()已被删除…。最后,我使用命令:ALTER USER'root'@'localhost'通过'password'标识为mysql\u native\u password您的回答帮助我找到了正确的方法,谢谢。嘿@Mikey Mike您能解释一下您在哪里键入ALTER USER。。。查询来解决您的问题,是在mysql提示符下,我尝试在那里键入它,但所发生的只是箭头提示符->,我仍然有错误
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)