python3 load data infile for mysql5.7

def load():
global myConn
sql = "truncate table test"
myConn.execute(sql)
print('truncate table success')

# 加参数也可 character set gbk
# 换行键: \n==\x0A==chr(10),ord('字符')==数字,chr(数字)=字符
# 标题开始:^A==\x01==chr(1)
# 双引号: \"==\x22==chr(34)
    sql = """load data infile '/home/ccx/test.txt' into table test 
fields terminated by ',' enclosed by '\x22' lines terminated by '\x0A'"""
myConn.execute(sql)
print('load data infile success')
posted @ 2019-10-12 20:44  舟山渔夫  阅读(590)  评论(0编辑  收藏  举报