1

I am not a network/web/internet programmer so please excuse my noobness in this area. I have gotten a website using a free hosting service. They include one MySQL database. Here are the details for the database:

port = 3306
host = "fdb4.biz.nf"
database = "1284899_6067"
user = "1284899_6067"
password = "somepass9351"

I am using MySQLdb module (installed on my CLIENT machine - not server) to connect to this database:

db = MySQLdb.connect(host=host, user=user, passwd=password, db=database,port=port)

But I get the following error:

OperationalError: (2003, "Can't connect to MySQL server on 'fdb4.biz.nf' (10060)

What I have already tried

  • tried two different databases from different hosts
  • tried changing the port
  • tried searching SO for similar answers but all others connect to 'local host'

What I think:

  • could this be caused by my firewall? I am using my school's internet. I don't think this could be it because I am on CLIENT so if anything it is the SERVER'S firewall.

Two questions

  1. Can MySQLdb be used to connect to a db on a SERVER when it is imported on a CLIENT?
  2. If yes, what am I doing wrong?

Thank you so much for any help, its greatly appreciated! Been stuck the whole day on this.

MeLikeyCode
  • 297
  • 4
  • 13

2 Answers2

2

For security reasons, mysql only listens for connections from localhost. Error code 10060 is basically that: you are not allowed to connect remotely.

Solution: find a my.ini (or my.cnf in linux) and try to find a line:

bind-address = 127.0.0.1

this line says: allow only local connections. So, you should comment-out this line, or set your IP address.

Kenan Zahirovic
  • 1,587
  • 14
  • 24
  • Do hosts usually give you read/write access to this file? Wouldn't something like this effect all "websites" of that host? Where would I usually find this file? Thank you SO much for your help btw! – MeLikeyCode May 31 '14 at 00:20
  • I guess MySQL server is on linux, right? Regarding location of my.cnf, see this link: http://stackoverflow.com/questions/2482234/how-to-know-mysql-my-cnf-location – Kenan Zahirovic May 31 '14 at 00:27
  • Changing bind-address is kind of security risk, but at this moment most important thing for you is to connect to your database. You should take care about this latter. if you have fixed IP address, set it right now. – Kenan Zahirovic May 31 '14 at 00:34
  • Thanks again for the help but I've run into another problem. My python program will be running on various different computers. I will have to either allow remote host (which you say is a security risk) or whitelist a TON of ip addresses. Is there a better way for me to allow my python program to run on many different computers but access/manipulate the same online database? I would appreciate a link or some keywords for me to research. – MeLikeyCode May 31 '14 at 02:03
0

Yes, MySQLdb can connect to remote hosts.

And your usage of the connect method is correct.

You should first check if you can connect to the remote mysql server from your mysql client.

In terminal you can type mysql -h hostname -u username -p databasename This should prompt you for the password. Enter the password. Can you connect?

If you can't connect, then you have an access problem, and its not a python - mysqldb problem

Either the server is not reachable because it is behind a firewall, in that case your client machine's ip needs to be whitelisted. Check your firewall settings

Or, the mysql server running on the remote machine is configured to accept only local connections. I think this is the default, but I'm not sure. You should ssh into the server remote host where the database server is running, locate the my.cnf file on the server and check the settings. Depending on your mysql version, the configuration would look slightly different.

Or, the user that you're trying to connect as is not associated with the ip that you're trying to connect from. Mysql users have two parts, like this: 'username'@'host'. To enable a user to connect from all ips the user needs to look like this 'user'@'%'.

I hope I've given you enough to try to debug this issue.

Haleemur Ali
  • 26,718
  • 5
  • 61
  • 85