【问题标题】:Mysql-python can't connect to localhost server on Windows 7Mysql-python 无法连接到 Windows 7 上的本地主机服务器
【发布时间】:2013-04-22 08:22:58
【问题描述】:

我有一个本地 mysql 服务器在 localhost,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,所以我不能切换连接器。

【问题讨论】:

    标签: python mysql django windows mysql-python


    【解决方案1】:

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

    【讨论】:

    • 用端口 3306 和 127.0.0.1 试过,没用,我没办法
    • 安装 wampxamp 并让它们运行您的本地主机服务器应该可以快速修复......不知道实际问题是什么
    • 不要问我为什么,但是重新启动 Windows 解决了这个问题。我打算删除问题,或者自己回答..
    • 但你是对的,使用 localhost 现在它不起作用,所以我需要设置127.0.0.1
    猜你喜欢
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 2021-08-04
    相关资源
    最近更新 更多