2015-07-20 47 views
-1

我是新手到python,我有简单的代码来连接数据库使用MySQLdb和Python3.4在本地主机上运行。使用MySQLdb的错误

Python代码:

#!c:/Python34/python.exe -u 
import cgitb ,cgi 
import sys 
import MySQLdb 
conn = MySQLdb.connect(host='localhost',port=3306, 
             db='example2', 
             user='root', 
             password='tiger') 
cursor = conn.cursor() 
if conn: 
    print("sucess") 

但得到错误,在执行代码 错误:

Traceback (most recent call last): 
    File "<pyshell#27>", line 4, in <module> 
    password='tiger') 
    File "C:\Python34\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect 
    return Connection(*args, **kwargs) 
    File "C:\Python34\lib\site-packages\MySQLdb\connections.py", line 204, in __init__ 
    super(Connection, self).__init__(*args, **kwargs2) 
TypeError: an integer is required (got type str) 

请给些建议

+0

请不要编辑错误的问题。你的问题现在无法使用。 – Matthias

回答

0

你需要从港口卸下单引号。

conn = MySQLdb.connect(host='localhost', 
         port=3306, 
         database='example2', 
         user='root', 
         password='tiger') 
+0

得到错误的回溯(最近通话最后一个): 文件 “”,4号线,在 密码= '虎') 文件 “C:\ Python34 \ LIB \站点包\ MySQLdb的\ __ init__.py” ,第81行,连接 返回连接(* args,** kwargs) 文件“C:\ Python34 \ lib \ site-packages \ MySQLdb \ connections.py”,第204行,在__init__中 super(Connection,self) .__ init __(* args,** kwargs2) TypeError:'password'是该函数的无效关键字参数 – user092

+0

它是“passwd”,而不是“password”。 –

+0

噢耶。我通常使用mysql网页中的mysql连接器,并使用密码http://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html – NewJavaPythonDev