csv文件导入mysql数据库表中:
load data infile 'F:/eclipse2/tianchi_fresh_comp_train_user.csv'
into table `shopping_records_original`
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by '\n';
数据库表导出到csv文件:
select * from `shopping_records_original`
into outfile 'F:/eclipse2/tianchi_fresh_comp_train_user.csv'
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by '\n';
python连接mysql数据库:
import pymysql
conn = pymysql.connect(user='root', passwd='root',
host='localhost', db='zjctest')
cur = conn.cursor()
cur.execute("SELECT * FROM zjc")
for r in cur:
print("row_number:" , (cur.rownumber) )
print("id:"+str(r[0])+"name:"+str(r[1])+"age:"+str(r[2]))
cur.close()
conn.close()