我在学习《Python从入门到精通》中的14.3.4中,严格按照书中的代码编写执行后报错:
Warning (from warnings module):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\cursors.py", line 170
result = self._query(query)
Warning: (1051, "Unknown table 'mrsoft.books'")
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\conn3.py", line 15, in <module>
cursor.execute(sql)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\cursors.py", line 170, in execute
result = self._query(query)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\cursors.py", line 328, in _query
conn.query(q)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\connections.py", line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\connections.py", line 732, in _read_query_result
result.read()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\connections.py", line 1075, in read
first_packet = self.connection._read_packet()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
packet.check_error()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\err.py", line 109, 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 'data DEFAULT NULL, \n PRIMARY KEY (id)\n ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT ' at line 6")
我用的是Python3.8 和 MySQL8.0 版本,敬请老师答疑,不胜感激!