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.
|
|
|
|
# -*- 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("<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}")
|