Thread: Python & MySQL

Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    74
    Rep Power
    11

    Python & MySQL


    I'm just starting to learn python, and I want to know what classes or modules there are for interaction with a MySQL with python, thanks in advanced for any help.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    26
    Rep Power
    0
    There is a module named MySQLdb. It's a mysql wrapper. I think you can find it on sourceforge.net. I don't think it is being maintained any more.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12
    As said by deflator...MySQLdb is the module you have to eye on. There's a very nice overview in our devshed articles section ...you could have a go at it!

    MySQL Connectivity With Python

    Peace,
    Subha
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Hello I have already asked this question but haven't got a very clear response, I was wondering if someone could help me with this problem. My problem is that I have both MySql and Python on my computer but the Python is not able to detect the MySQL. I have looked at the DevShed article which says:
    The first thing to do is make sure that you have the MySQLdb module installed on your
    Python development system. The easiest way to check this via the interactive Python
    command line interpreter − as the following example demonstrates:
    But this is for Linux. I have a Windows XP computer. On the MySQLdb documentation, they also say if you have Windows we can't help you much!
    Does anyone know where I have to put mySQLdb in order for python to detect it?

    Thanks alot for your help.
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I've never had a problem with MySQLdb on Windows I will admit that it took me a few tries to get it working on my Mac . Anyway, download the latest compatible .exe from sourcforge and run it. This will add the module to Pythons site-packages directory (where it will be seen). Next:

    In the article, when the author talks about the "interactive Python command line interpreter" he's actually talking about the Python shell. If you fire up IDLE (or run python from cmd) you'll see pretty much the same thing as shown in the article. Follow the instructions and you should be away .

    There is also the possibility that the problem is with the MySQL installation so you might want to check that this is accessible. For instance, if you have PHP on your system and it works with MySQL already then you know everything's fine .

    I can't remember your post sorry, if I'd seen it I'm sure i would have replied: will have a look for it.

    Edit: You can find the latest source/binary distributions at the page below; anyone interested in the Mac binary can email me.

    http://sourceforge.net/projects/mysql-python

    Hope this helps,

    Mark.
    Last edited by netytan; January 20th, 2005 at 05:19 PM. Reason: Added URL to project Homepage.
    programming language development: www.netytan.com Hula

  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Thanks alot Netytan for your post. I appreciate your help. Well basically I think my problem is that I mySqldb on my computer is installed somewhere that is unknown to Python.
    I mean when mySqldb was intalling on my computer, it asked me where I wanted to intall it and I selected the program files folder. In some postings I see people talk about "site packages". Should I have installed the mySqldb in this folder? If that's the case should I now just drag mySqldb folder into this folder?
    My problem currently is that when I type "import mysqldb" in python shell, it says no such module exists.

    Your help is greatly appreciated.
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You have too options, you could set the $PYTHONPATH variable to include the location of MySQLdb; this can also be done by editing sys.path. Although I wouldn't bother with this, just run the uninstaller for MySQLdb then reinstall it in the default place (don't change any of the settings this will put the module in site-packages).

    That should do it ,

    Mark.
    programming language development: www.netytan.com Hula

  14. #8
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Since you are using Windows, you could also use ADO to connect to MySQL. Using ADO isn't portable to other OSs, but it kicks some solid butt on the platform that it works on. I wrote a tutorial on using ADO a while back. Let me know if you want the link.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Mark thanks alot for your help. I'll look into it, hopefully it'll start working.

    Hi Scorpions4ever, thanks for your posting, yes it would be great to look at that tutorial. I have recently heard about ADO, but to be honest I don't know much about it. Is it related to PHP? IIS? Sorry I'm clueless about it!
  18. #10
  19. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Hi Mark, I uninstalled MySqldb and reinstalled it again. It's actually a .zip file and it asks you if you want to unzip it to a temporary folder. So basically it doesn't have a suitable "default" location for installation. I chose the "Site Packages" in Python folder but still the same problem persists and when I type "import mysqldb" in Python shell, it says that no such module exits.
    Which file is it that I can add a PATH variable to it?

    Thanks alot,
  22. #12
  23. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    By "Site Packages" do you mean "C:\Python2X\Site Packages\" or the site-packages directory, "C:\Python2X\Lib\site-packages\".

    If you want to permanently append a path to sys.path then you should so it in "site.py". Do a search for these [site-packages & site.py] if you cant find them but both should be in your lib directory .

    Night,

    Mark.
    programming language development: www.netytan.com Hula

  24. #13
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    174
    Rep Power
    11

    win32 exe link for mysqldb module


    Here's the actual .exe link from the sourceforge website as of today, January 26, 2005. If the zip's are not working for some reason, the exe will install to the /lib/site-packeges directory (hopefully) correctly.

    If this link doesn't work, look more closely in the Files section of http://sourceforge.net/projects/mysql-python and the last item of the 1.0.0 section is the .exe Windows installer.

    http://prdownloads.sourceforge.net/mysql-python/MySQL-python.exe-1.0.0.win32-my4.1-py2.3.exe?download

    cheers
  26. #14
  27. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    174
    Rep Power
    11
    oh, just a note that I believe if you're using any pre-version 4 of MySQL, (3.2x etc) you'd have to use a different older mysqlbd module. Can someone verify this?

    thanks
  28. #15
  29. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    From what I can see it looks like MySQLdb should work with any version from 3.22 although MySQL 4 support is currently in the Alpha according to the docs shipped with MySQLdb 1.0.1, though I don't think these are up to date. You'd have to test it to be sure .

    Mark.
    programming language development: www.netytan.com Hula

Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo