鍍金池/ 問答/數(shù)據(jù)分析&挖掘  Java  Python  數(shù)據(jù)庫/ mysql 連接器 python,NotSupportedError

mysql 連接器 python,NotSupportedError

從Mongodb導(dǎo)出一批 Json 數(shù)據(jù),需要轉(zhuǎn)到 Mysql,但是導(dǎo)出的 Json 格式無法直接寫入mysql,就想著先把數(shù)據(jù)轉(zhuǎn)為Pandas的dataframe,然后再通過dataframe寫入sql:

import pandas as pd
from sqlalchemy import create_engine
import json


def json_to_sql(jsonfile, sqlname):
    df = pd.read_json(jsonfile, lines=True)
    conn = create_engine('mysql+mysqlconnector://root:123456@localhost:3306/ScientificName?charset=utf8')
    for i in range(len(df)):
        df['chromosomes'][i] = json.dumps(df['chromosomes'][i][0], ensure_ascii=False)
    print(df['chromosomes'][0])
    df.to_sql(name=sqlname, con=conn, if_exists='append', index=False)
        

json_to_sql('/Downloads/數(shù)據(jù)表JSON-20180118/speciesHengduan.json', 'speciesHengduan')

結(jié)果運(yùn)行時(shí)總是報(bào)錯(cuò),用的 mysql 版本是 8.0.11:

NotSupportedError: (mysql.connector.errors.NotSupportedError) Authentication plugin 'caching_sha2_password' is not supported (Background on this error at: http://sqlalche.me/e/tw8g)
回答
編輯回答
艷骨

MySQL8在這里和低版本不兼容,你可以重新安裝MySQL(或者用Reconfigure選項(xiàng)),把認(rèn)證的選項(xiàng)設(shè)置為“Use Legacy Authentication Method”, 或者你如果不是必須要用MySQL 8,可以降級(jí)到低版本。

2017年11月10日 04:01