當前位置:成語大全網 - 新華字典 - 怎麽用python將文本文件裏的數據導入到mysql數據庫

怎麽用python將文本文件裏的數據導入到mysql數據庫

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()