就在今天,我决定要学习 python,因为我个人喜欢它的语法和感觉。我是一个非常年轻的开发人员,我真的很想学习一门新的编程语言,因为我只精通JavaScript(尤其是 javascript),PHP所以我决定使用Python. Python 看起来很像 javascript execpt,因为它们不使用花括号来定义新块。当然,它的功能要强大得多。
我了解到您可以MySQL使用MySQLdb.
但是当我使用以下代码时,我遇到了问题。
db = MySQLdb.connect(host="localhost", user="methodjs_postes", passwd="********", db="methodjs_postes");
我收到这个大错误:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
db = MySQLdb.connect(host="localhost", user="methodjs_postes", passwd="********", db="methodjs_postes");
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)")
我真正关注的主要部分是Can't connect to MySQL server on 'localhost' (10061)部分。(但如果你也解释其他部分会很好)
我不明白为什么我会遇到这个问题。我用localhost在我的PHP,它工作得很好。而且我做import了MySQLdb我认为不是错误的事情,因为那时它甚至不会尝试连接。
我正在使用python 2.7,我将使用 3.3(已下载),但MySQLdb最多仅支持 2.7。
使用时select User,Host,Password from mysql.user where User like '%methodjs_postes%';出现以下错误:
SELECT command denied to user 'methodjs'@'localhost' for table 'user'