怎么用python将文本文件里的数据导入到mysql数据库
发布网友
发布时间:2022-04-08 01:28
我来回答
共1个回答
热心网友
时间:2022-04-08 02:57
with open("fileinfo.txt", "rt") as handle:
datas = [ln.split('\t') for ln in handle]
conn = MySQLdb.connect(host='localhost', user='mysql', passwd='', db='db')
curr = conn.cursor()
curr.executemany("insert into tb values (?, ?, ?)", datas)
conn.commit()
追问不行,不过还是谢谢tim_spac,我用其它方法:python执行mysql自带的导入功能LOAD DATA