Results 1 to 3 of 3

Thread: python remote database connection

  1. #1
    Join Date
    Apr 2006
    Location
    Atlanta, GA USA
    Beans
    207
    Distro
    Ubuntu 18.10 Cosmic Cuttlefish

    python remote database connection

    Hi all, I am learning python and wonder if I can connect to a mySQL database server hosted by my hosting service (bluehost). The script just hangs with no response.

    Disclaimers:
    • I'm not sure what a port is, nor how to use it.
    • I have a link that will get me phpmyadmin on the bluehost server. The format of the link is like this: http://AA.BB.CC.DD:YYYY/3rdparty/phpmyAdmin/index.php
    • Notice I removed the ip numbers
    • I am on a laptop that is behind a firewall (linksys router).
    • Bluehost forums say something about being whitelisted. Not sure what this means either.

    Code:
    import MySQLdb
    myDB = MySQLdb.connect(host="AA.BB.CC.DD", port=YYYY, user="**********", passwd="*****************")
    cHandler=myDB.cursor()
    cHandler.execute("SHOW DATABASES")
    results=cHandler.fetchall()
    print "========================="
    for items in results:
    	print items[0]
    Last edited by braddcadd; May 5th, 2007 at 11:13 PM.

  2. #2
    Join Date
    Aug 2006
    Beans
    26
    Distro
    Ubuntu 6.10 Edgy

    Re: python remote database connection

    You're doing pretty well so far. The problem is most likely that when you connect via phpMyAdmin, the PHP process is on BlueHosts's own servers; when you're connecting via your script, your IP address probably isn't being accepted. You'll need to go into your hosting settings, find the MySQL settings, and just set the accepted hosts to be a wildcard - Variously a %, *, or other charachter. It should be documented there.

  3. #3
    Join Date
    Jun 2005
    Beans
    2,314

    Re: python remote database connection

    Your code looks right to me. But if your ISP has any sense at all, they won't allow just anyone to connect to their database. You will probably have to talk to them and get them to add you to their list of IP addresses that are allowed to talk to their database server (such a list is called a whitelist, as opposed to a blacklist which would list people who are not allowed). This may be doubly difficult if you have a dynamic IP address.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •