python连接到mySql错误 - ConnectionRefusedError:[WinError 10061]

时间:2016-02-01 20:34:10

标签: python mysql python-3.x connection database-connection

我尝试使用python连接mySql服务器,这是我的代码(当然我将数据库细节更改为假的):

    import pymysql
    connMySql= pymysql.connect (
    host = "blahblah.ipagemysql.com",
    user = "blah",
    passwd = "1234",
    db = "db_book")

    cur = connMySql.cursor()
    print ("writing to db")
    connMySql.commit()

此程序会出现以下错误:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\connections.py", line 836, in connect
    (self.host, self.port), self.connect_timeout)
  File "C:\Python34\lib\socket.py", line 509, in create_connection
    raise err
  File "C:\Python34\lib\socket.py", line 500, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/proj/projpy.py", line 432, in <module>
    db = "db_book")
  File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\__init__.py", line 88, in Connect
    return Connection(*args, **kwargs)
  File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\connections.py", line 657, in __init__
    self.connect()
  File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\connections.py", line 882, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'blahblah.ipagemysql.com' ([WinError 10061] \u200f\u200f)")

任何想法如何解决?

2 个答案:

答案 0 :(得分:1)

我收到同样的错误,直到我加入&#34;端口&#34;您服务器可能需要的参数?

connection = pymysql.connect(host = host,
                       user = user,
                       db = db,
                       password = password,
                        port = port)

答案 1 :(得分:0)

检查&#34; blahblah.ipagemysql.com&#34; MySQL服务器正在侦听localhost(127.0.0.1)并在必要时进行更改。