Python使用mysqldb连接mysql抛出errorclass errorvalue?
大家讲道理
大家讲道理 2017-04-18 10:23:10
0
1
1472

系统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)

在网上搜索了错误原因,却没有找到类似的问题,想请问一下这里为什么会抛出错误类/错误值,我看了一下,没有发现问题...,希望得到大家的帮助。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

répondre à tous(1)
Peter_Zhu

Python3 ne prend plus en charge MySQLdb.
http://stackoverflow.com/ques...

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!