1

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?

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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

4 Comments

is it Linux or Windows or something else server? I mean: "blahblah.ipagemysql.com"
dev.mysql.com/doc/refman/5.7/en/option-files.html you may also try to check it, using telnet: [telnet blahblah.ipagemysql.com 3306], if MySQL is listening on the standard (3306) port...
This is a my sql server from ipage.com. If this is what you meant
OK, does it work with the mysql client: [mysql --host=blahblah.ipagemysql.com --user=blah --password=1234 db_book] ? you should start that command from the same server/machine where you're starting your python program

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.