开发者

MySQL-python Cannot connect to server

This is driving me crazy.

I have Python 2.5 and MySQL-python-1.2.3 from the .exe available here installed on Vista.

I have been making .php pages over the past few weeks and connected fine in order to test them in my browser.

$dbcnx=@mysql_connect("localhost", "root", "mypassword")

I have also been using mysql commandline with

mysql.exe -uroot -pmypassword just fine.

However, wh开发者_开发问答en I try to use MySQLdb with

conn = MySQLdb.connect(host = "localhost", user = "root", passwd = "mypassword") 

I get

OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

I have checked that MySQL is running in services. I checked my MySQL config in my.ini and it is running on port=3306. I have even uninstalled and reinstalled MySQL 5.1. I read several pages of connection problems and answers on Google, but haven't yielded anything. It must be something simple I am overlooking, but does anyone have any more ideas?


Don't use the windows version (all my relevant experience is on Linux), but I'd be willing to bet it will work if you use 127.0.0.1 in place of localhost.

Edit: -- a bit of explanation.

Firstly, check the entries in mysql.user table, for the host field (although by default, you probably have three entries for root which cover all bases). Most likely, your problem is caused by the fact that the MySQL service is listening on 127.0.0.1:3306, not localhost:3306, and your hosts file or other routing config is not being invoked properly by the python interpreter.


Make sure you have opened the TCP port 3306 in your firewall for connections.

Also see this question Can't connect to MySQL server on 'localhost' (10061)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜