Mysql-python无法连接到Windows 7上的localhost服务器

时间:2013-04-28 17:24:44

标签: python mysql django windows mysql-python

我有一个在localhost上运行的本地mysql服务器,Windows 7

C:\web>mysqld --console
[...]
130428 19:12:37 [Note] mysqld: ready for connections.
Version: '5.5.31-log'  socket: ''  port: 3306  MySQL Community Server (GPL)

如果我尝试连接mysql,我没有问题(root没有密码)

C:\Users\Alle>mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.31-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use information_schema
Database changed
mysql>

但是当我尝试通过MySQL-Python 1.2.4连接到mysql时,失败

C:\Users\Alle>python
Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> MySQLdb.connect('localhost', 'root', '', 'information_schema')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

这是我的conf

我坚持这一点,我不知道该怎么做..我能做些什么来调试问题并让mysql-python工作?我需要这个用于Django,所以我无法切换连接器。

1 个答案:

答案 0 :(得分:3)

尝试127.0.0.1而不是localhost未正确映射,或者您还需要在连接中包含该端口?