如何使用python将管道加载到mysql加载数据infile?以下似乎不起作用。本地infile期望文件,因此不确定它是否因此失败。
cat = Popen(["cat /Users/test/filename.out"], stdout=PIPE, bufsize=-1, shell=True)
load = """load data local infile - into table %s fields terminated by '|' lines terminated by '\\n';""" % (tablename)
with conn:
cursor = conn.cursor()
for line in cat.stdout:
cursor.execute(load.stdin.write(line))
cat.stdout.close()
cat.wait()
load.stdin.close()
load.wait()