sql语句是保存在sql.sql文件中的全是INSERT语句, 未遗漏 " ; "
**
如下代码可执行
**
with open('sql/sql.sql', "r", encoding="utf-8") as f:
for each_line in f.readlines():
if not each_line or each_line == "\n":
continue
cur.execute(each_line.strip())
conn.commit()
但拼接sql后就报错
with open('sql/sql.sql', "r", encoding="utf-8") as f:
for each_line in f.readlines():
if not each_line or each_line == "\n":
continue
elif count < 50:
sql += each_line.strip()
count += 1
else:
cur.execute(sql)
conn.commit()
sql = each_line
count = 1
if sql:
cur.execute(sql)
conn.commit()
错误信息
Traceback (most recent call last):
File "main.py", line 135, in <module>
db.readSQL()
File "db.py", line 118, in readSQL
cur.execute(sql)
File "d:\Anaconda3\App\lib\site-packages\pymysql\cursors.py", line 165, in execute
result = self._query(query)
File "d:\Anaconda3\App\lib\site-packages\pymysql\cursors.py", line 321, in _query
conn.query(q)
File "d:\Anaconda3\App\lib\site-packages\pymysql\connections.py", line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "d:\Anaconda3\App\lib\site-packages\pymysql\connections.py", line 1061, in _read_query_result
result.read()
File "d:\Anaconda3\App\lib\site-packages\pymysql\connections.py", line 1349, in read
first_packet = self.connection._read_packet()
File "d:\Anaconda3\App\lib\site-packages\pymysql\connections.py", line 1018, in _read_packet
packet.check_error()
File "d:\Anaconda3\App\lib\site-packages\pymysql\connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "d:\Anaconda3\App\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, "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 'INSERT INTO abc (字段名省略(显示不全),' at line 1")
请问这该怎么办?
还有, 数据库报错
Got a packet bigger than 'max_allowed_packet' bytes
my.ini中max_allowed_packet=500M
重启数据库就好....
4 回答
波斯汪
TA贡献1811条经验 获得超4个赞
pymysql.err.ProgrammingError: (1064, "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 'INSERT INTO abc (字段名省略(显示不全),' at line 1") 明显的有个语法错误,检查你的sql.sql文件
添加回答
举报
0/150
提交
取消