-----\n") query = """load data local infile"""+' '+path+' '+"""into table"""+' '+tbname+' '+"""fields terminated by"""+' '+"'|'"+' '+"""lines terminated by"""+' '+"'"+lt+"'"+' '+"""ignore 1 lines;""" cur.execute(query)它在我的本地windows系统中工作。 在上面的代码“fname”:文件名和“path”:文件路径 我正在使用mysql.connector.connect进行db连接在我运行load语句后出现以下错误,任何帮助都将不胜感激。提前谢谢。 错误:Traceback (most recent call last): File "load_to_mysql.py", line 73, in cur.execute("""load data local infile"""+' '+path+' '+"""into table"""+' '+tbname+' '+"""fields terminated by"""+' '+"'|'"+' '+"""lines terminated by"""+' '+"'"+lt+"'"+' '+"""ignore 1 lines"""+";") File "/usr/local/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 551, in execute self._handle_result(self._connection.cmd_query(stmt)) File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 490, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 395, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/home/ubuntu/pythonscript/ftp/INV_COST_FEED_GARBJ_20180417_00.txt into table ftp' at line 1 ubuntu@ip-X-X-X-XXX:~/pythonscript/ftp$ nano load_to_mysql.py`
3条答案
按热度按时间col17t5w1#
---------load starts for "+tbname+"
pgccezyw2#
-----\n") query = """load data local infile"""+' '+path+' '+"""into table"""+' '+tbname+' '+"""fields terminated by"""+' '+"'|'"+' '+"""lines terminated by"""+' '+"'"+lt+"'"+' '+"""ignore 1 lines;""" cur.execute(query)
它在我的本地windows系统中工作。 在上面的代码“fname”:文件名和“path”:文件路径 我正在使用mysql.connector.connect进行db连接在我运行load语句后出现以下错误,任何帮助都将不胜感激。提前谢谢。 错误:
Traceback (most recent call last): File "load_to_mysql.py", line 73, in cur.execute("""load data local infile"""+' '+path+' '+"""into table"""+' '+tbname+' '+"""fields terminated by"""+' '+"'|'"+' '+"""lines terminated by"""+' '+"'"+lt+"'"+' '+"""ignore 1 lines"""+";") File "/usr/local/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 551, in execute self._handle_result(self._connection.cmd_query(stmt)) File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 490, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 395, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/home/ubuntu/pythonscript/ftp/INV_COST_FEED_GARBJ_20180417_00.txt into table ftp' at line 1 ubuntu@ip-X-X-X-XXX:~/pythonscript/ftp$ nano load_to_mysql.py`8fsztsew3#
似乎缺少文件路径周围的引号
在第1行使用“/home/ubuntu/pythonscript/ftp/inv\u cost\u feed\u garbj\u 20180417\u 00.txt into table ftp”的语法
见文件
文件名必须以文本字符串形式给出。在windows上,将路径名中的反斜杠指定为正斜杠或双反斜杠。character \u set \u filesystem系统变量控制文件名的解释。