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...
相关文章:
1. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)2. 环境搭建 - anaconda 创建python2.7环境中打开编译器确是3.6版本3. extra没有加载出来4. linux - Ubuntu下编译Vim8(+python)无数次编译失败5. html5 - H5页面唤起APP导航6. javascript - 弹出一个子窗口,操作之后关闭,主窗口会得到相应的响应,例如网站的某些登录界面,django后台的管理等,这是怎么实现的呢?7. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?8. mysql replace 死锁9. list - python 求助10. python - 数据与循环次数对应不上
