You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
716 B
33 lines
716 B
# -*- coding: gbk -*-
|
|
import pymysql
|
|
import pandas as pd
|
|
# -*- coding: <encoding name> -*-
|
|
|
|
|
|
db_config = {
|
|
'host': 'localhost',
|
|
'port': 3306,
|
|
'user': 'root',
|
|
'password': '21412030117',
|
|
'database': 'word',
|
|
'charset': 'utf8mb4',
|
|
}
|
|
|
|
|
|
try:
|
|
connection = pymysql.connect(**db_config)
|
|
cursor = connection.cursor()
|
|
extracted='words.csv'
|
|
data_to_insert= pd.read_csv(extracted)
|
|
|
|
|
|
for item in data_to_insert:
|
|
xuhao, neirong = item
|
|
insert_sql = "INSERT INTO word (xuhao, neirong) VALUES (%s, %s)"
|
|
cursor.execute(insert_sql, (xuhao, neirong))
|
|
|
|
|
|
connection.commit()
|
|
print("数据插入成功!")
|
|
except Exception as e:
|
|
print(f"数据插入失败,错误信息:{e}") |