gracewyc
gracewyc
2017-02-28 05:28

pytho使用mysql链接问题

  • raise errorclass
  • errorvalue
  • mysql

运行如下代码:

 import MySQLdb

conn = MySQLdb.connect(host='localhost',user='root',passwd='123456')

curs = conn.cursor()

conn.select_db('mytest_db')

curs.execute("create table test(id int,message varchar(50))")

value = [1,"davehe"]
curs.execute("insert into test values(%s,%s)",value)

curs.execute("select * from test")
#values = []

conn.commit()

curs.close()

conn.close()

有如下错误:

  • Traceback (most recent call last): File "python_mysql.py", line 3, in conn = MySQLdb.connect(host='localhost',user='root',passwd='123456') File "/usr/local/lib/python3.4/dist-packages/MySQL_python-1.2.5-py3.4-linux-x86_64.egg/MySQLdb/__init__.py", line 80, in Connect from MySQLdb.connections import Connection File "/usr/local/lib/python3.4/dist-packages/MySQL_python-1.2.5-py3.4-linux-x86_64.egg/MySQLdb/connections.py", line 36 raise errorclass, errorvalue ^ SyntaxError: invalid syntax

求大神指导啊。我用的是python3.4

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答