Python-ExcelをMySQLに直接保存するための数行のコード

要件:保存のためにExcelファイルをデータベースにインポートします。
注:Excelテーブルのすべての記号はすべて英語です!!!

デモファイル:
ここに画像の説明を挿入実装コード:

import pymysql
import pandas as pd
from sqlalchemy import create_engine

file = r'./data.xlsx'
df = pd.read_excel(file)
engine = create_engine("mysql+pymysql://root:root@localhost:3306/python",encoding='utf-8')

df.to_sql('testexcel',con=engine,if_exists='replace',index=False)

実行結果:
ここに画像の説明を挿入
参照:Excelをデータベースに保存

おすすめ

転載: blog.csdn.net/weixin_45666249/article/details/114317951