值(第1行的“2”)

6mzjoqzu  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(122)

我是python新手。我试着写skcript来解析mysql。我的部分代码:

db = MySQLdb.connect(host="localhost", user="me", passwd="passwd", db="Data")

with db:
  cursor = db.cursor()    
  with open("my.log","rw") as f:
    next(f)
    for line in f:
    result = parser(line)
    resultS = parserS(result[3])
    format = '[%a %b %d %H:%M:%S.%f %Y]'
    now = datetime.datetime.strptime(result[0], format)

    sql = ("INSERT INTO Data.table1 (time, level, id, error, file ,ip, request) VALUES (%s, %s, %s, %s, %s, %s, %s)")
    data = (now.strftime('%Y-%m-%d %H:%M:%S %f'), result[1], result[2], ' ' ,resultS[0],resultS[1],resultS[2])
    cursor.execute(sql, data)

f.close()
db.close()

当我试着运行它时,给我一个信息:

Traceback (most recent call last):
  File "parsingApacheErrorFrom.py", line 81, in <module>
    cursor.execute(sql, data)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 226, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-error (time, log_level, pid, error_status, file ,client_ip, message) VALUES ('2' at line 1")

我试图找出我的sql语法中的错误,但它看起来很好。我不明白什么意思:值('2'在第1行“)???在mysql表中,第一列是datetime类型,其他所有列都是varchar(255)。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题