jaldk
jaldk

Reputation: 113

python connect to mySql error-ConnectionRefusedError: [WinError 10061]

I tried to connect mySql server, using python, this is my code(of course I changed the dataBase details to fake ones):

    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()

this program give this following error:

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)")

any idea how to solve it?

Upvotes: 1

Views: 5469

Answers (2)

sparrow
sparrow

Reputation: 11470

I was getting that same error until I included the "port" parameter which may be necessary for your server too?

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

Upvotes: 1

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210982

check whether the "blahblah.ipagemysql.com" MySQL server is listening on localhost (127.0.0.1) and change it if necessary.

Upvotes: 0

Related Questions