MySQL Connector in Python
Question: Trying to connect to my MySQL DB on my VPS. I'm getting the following error,
when using the below code;

(I've stripped out my credentials - however I know they work, as I use them
for my PHP dev as well.

**CODE**

    
    
    import mysql.connector as mysql
    from mysql.connector import errorcode
    
    try:
      conn = mysql.connect( user= %USER%
                            ,password=%PW%
                            ,host = %HOST%
                            ,database = %DB%
        )
    except mysql.Error as err:
      if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print("Something is wrong with your user name or password")
      elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print("Database does not exists")
      else:
        print(err)
    else:
        conn.close()
    

**ERROR MESSAGE**

    
    
    2003: Can't connect to MySQL server on '%HOST%:3306' (10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established   connection failed because connected host has failed to respond)
    

**Connector That I'm using**

<http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-
python-2.0.1-py3.4.msi>

Any idea what I'm doing wrong?


Answer: Check the [GRANT](http://dev.mysql.com/doc/refman/5.5/en/grant.html) on your
MySQL database. It might be that you haven't been GRANTed permission to
connect from that host with the given username and password.

The MySQL error number is 2003. I usually find it helpful to do a Google
search to see if others have had the problem:

<http://dev.mysql.com/doc/refman/5.0/en/access-denied.html>

Is there a firewall between the client machine and the database server? I
would hope that port 3306 would be blocked by default. If that's true, you'll
need to set up a firewall rule to allow access from the client IP to the
database IP via port 3306.

