我使用mysqlimport(和python)导入一堆记录。为了节省空间,我想对每个列使用gzip压缩。mysqlimport支持这个吗?在
现在我使用StringIO压缩每个列,然后使用mysqlimport转储行。有没有更有效的方法?据我所知,StringIO增加了不必要的开销:
# compress each of the columns
for col in d.values():
stringio = StringIO.StringIO()
gzip_file = gzip.GzipFile(fileobj=stringio, mode='w')
gzip_file.write(col)
gzip_file.close()
# mysql import script
fh = '/path/to/.sql'
command = ['mysqlimport',
'--fields-terminated-by=,',
'--fields-optionally-enclosed-by="', '-i', '-C',
'--columns=%s' % ','.join(d.keys()), '--local', fh]
FNULL = open(os.devnull, 'w')
p = subprocess.Popen(command, stdout=FNULL, stderr=subprocess.PIPE)
_, err = p.communicate()
目前没有回答
相关问题 更多 >
编程相关推荐