Rumah > Soal Jawab > teks badan
系统Ubuntu16,python3.5,mysql5.7
Python代码
conn = MySQLdb.connect(user="root" , passwd="123" , db="book_database" , charset="utf8")
cur = conn.cursor()
cur.execute("insert into book_db values(%s,%s,%s,%d)",("110","book","sxw",8))
conn.commit()
cur.close()
conn.close()
出错
Traceback (most recent call last):
File "/home/marshalldteach/PycharmProjects/sxwpython/first.py", line 2, in <module>
conn = MySQLdb.connect(user="root" , passwd="123" , db="book_database" , charset="utf8")
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/__init__.py", line 80, in Connect
from MySQLdb.connections import Connection
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 36
raise errorclass, errorvalue
^
SyntaxError: invalid syntax
数据库格式
desc book_db; | |||||
---|---|---|---|---|---|
Field | Type | Null | Key | Default | Extra |
book_id | char(20) | NO | PRI | NULL | |
book_name | char(20) | YES | NULL | ||
author | char(20) | YES | NULL | ||
amount | int(10) | YES | NULL |
4 rows in set (0.00 sec)
在网上搜索了错误原因,却没有找到类似的问题,想请问一下这里为什么会抛出错误类/错误值,我看了一下,没有发现问题...,希望得到大家的帮助。