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
715 B

6 months ago
# -*- coding: gbk -*-
6 months ago
import pymysql
import pandas as pd
# -*- coding: <encoding name> -*-
6 months ago
db_config = {
6 months ago
'host': 'localhost',
6 months ago
'port': 3306,
6 months ago
'user': 'root',
6 months ago
'password': '21412030117',
6 months ago
'database': 'word',
6 months ago
'charset': 'utf8mb4',
6 months ago
}
try:
6 months ago
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
extracted='data.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))
6 months ago
6 months ago
connection.commit()
print("<EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>")
except Exception as e:
print(f"<EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>{e}")