我正在使用以下代码进行连接:
import MySQLdb
db = MySQLdb.connect("localhost","root","root","test" )
cursor = db.cursor()
cursor.execute("SELECT * from student")
data = cursor.fetchone()
print "Database result : %s " % data
db.close()
我在运行文件时遇到以下错误:
Traceback (most recent call last):
File "C:/Python27/xsxs.py", line 5, in <module>
db = MySQLdb.connect("localhost","root","root","test" )
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
我该如何解决。