sql statements are
all INSERT statements saved in the sql.sql file, not omitted ";"
* *
< H2 > the following code can be executed < / H2 >* *
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()
but an error will be reported after splicing 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()
error message
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")
what should I do about this?
also, the database reports an error
Got a packet bigger than "max_allowed_packet" bytes
max_allowed_packet=500M
in my.ini
just restart the database.