import pymysql
#连接数据库
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='123456',
db='test',
charset='utf8',
)
cursor = conn.cursor()
f = open('C:\Users\zyl\Desktop\新建文件夹\shangweiwenjian.txt', "r",encoding = 'utf-8')
while True:
#逐行读取
line = f.readlines()
if line:
#处理每行
line = "".join(line)
line = line.strip('
')
line = line.split(",")
content = line[0]
cursor.execute(
"insert into article(content_detail) values(%s)",
[content])
else:
break
f.close()
cursor.close()
conn.commit()
conn.close()