表结构如下
No | Abstract |
1 | 人生无常,大肠包小肠 |
导出结果:
第一次写的是这样的,运行报错。
import pymysql
db = pymysql.connect(host='localhost',user='root',password='123456',port=3306,db='spiders')
cursor= db.cursor()
for i in range(1,2686):
sql='select Abstract into outfile 'D:/install/desktop/absman/{}.txt' lines terminated by'/r/n' from absman where No ={}'.format(i,i)
cursor.execute(sql)
db.commit()
sql= 这一行看起来也奇奇怪怪,看颜色也知道文件路径和enter符没有被识别到
突然想到是不是双引号单引号的问题,于是改为如下
import pymysql
db = pymysql.connect(host='localhost',user='root',password='123456',port=3306,db='spiders')
cursor= db.cursor()
for i in range(1,2686):
sql="select Abstract into outfile 'D:/install/desktop/absman/{}.txt' lines terminated by'/r/n' from absman where No ={}".format(i,i)
cursor.execute(sql)
db.commit()
成功