0

我有一个Python script调用 aPerl script来解析文件。解析后,PERL脚本生成一个输出,该输出将在脚本中加载到 MySQL 数据库Python

Python 脚本如下:

pipe = subprocess.Popen(["perl", "./parseGeneticCode.pl"], stdin=subprocess.PIPE)
pipe.stdin.close()
pipe = subprocess.Popen(["perl", "./makeTaxon.pl"], stdin=subprocess.PIPE)
pipe.stdin.close()

#Load taxon.out (output of makeTaxon.pl) in the database
sql10 = """LOAD DATA LOCAL INFILE 'gene_code.out' INTO TABLE geneticcode FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (ncbi_taxon_ID, parent_ID, taxon_name, taxon_strain, rank, geneticcode_ID, mitochondrial_geneticcode_ID);"""
try:
  c.execute(sql10)
  conn.commit()
  print "\nDone uploading in taxon\n"
except StandardError, e:
  print e
  conn.rollback()
conn.close()

sql9 = """LOAD DATA LOCAL INFILE 'taxon.out' INTO TABLE taxon FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (ncbi_taxon_ID, parent_ID, taxon_name, taxon_strain, rank, geneticcode_ID, mitochondrial_geneticcode_ID);"""
try:
  c.execute(sql9)
  conn.commit()
  print "\nDone uploading in taxon\n"
except StandardError, e:
  print e
  conn.rollback()
conn.close()

这些文件:taxon.outgene_code.out由 perl 脚本创建。但是我的 Python 脚本给出了一个错误:

(2, "File 'taxon.out' not found (Errcode: 2)")
(0, '')
Traceback (most recent call last):
  File "common_data.py", line 247, in <module>
    conn.rollback()
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')

两个文件gene_code.out都没有taxon.out上传。

4

1 回答 1

0

您需要显式配置 MySQL 服务器和客户端才能使用LOAD DATA LOCAL. 请参阅文档中的讨论。

于 2013-09-22T18:16:20.507 回答