Python使用mysqldb连接mysql抛出errorclass errorvalue?
问题描述
系统Ubuntu16,python3.5,mysql5.7Python代码
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;FieldTypeNullKeyDefaultExtrabook_idchar(20)NOPRINULL book_namechar(20)YES NULL authorchar(20)YES NULL amountint(10)YES NULL4 rows in set (0.00 sec)
在网上搜索了错误原因,却没有找到类似的问题,想请问一下这里为什么会抛出错误类/错误值,我看了一下,没有发现问题...,希望得到大家的帮助。
问题解答
回答1:python3 不在支持MySQLdb了。http://stackoverflow.com/ques...
相关文章: