Menu

MySQLdb for Python 2.5 on Mac

Help
2007-01-22
2012-09-19
  • Chuck Esterbrook

    This wasn't too bad to get working, but I had to read through some posts and make a couple attempts. Maybe this will save some people some time:

    My versions:
    Mac OS X 10.4.2
    Python 2.5
    MySQL 4.1 (that's what my production server is running, so...)

    Download the mysql-python-test version 1.2.2b2

    At the command line:

    $ tar xzf MySQL-python-1.2.2b2
    $ sudo bash
    $ cd MySQL-python-1.2.2b2

    Edit site.cfg and uncomment these three lines:

    mysql_root: /usr/local/mysql

    library_dirs: %(mysql_root)s/lib

    include_dirs: %(mysql_root)s/include

    $ export PATH=${PATH}:/usr/local/mysql/bin
    $ python setup.py install
    $ ^D # to get out of "sudo bash"

    To test:
    $ cd
    $ python
    >>> import MySQLdb
    >>> db = MySQLdb.connect('localhost', 'root', '', 'mysql')
    >>> cursor = db.cursor()
    >>> cursor.execute('select * from db')
    2L
    >>> db.close()
    >>>

    Enjoy your Mac,

    -Chuck

     
    • Andy Dustman

      Andy Dustman - 2007-01-22

      What happens when you use the default install? Or when you run mysql_config?

       
    • Chuck Esterbrook

      The first problem is that it cannot find one of the mysql files in the bin directory. Hence the export path.

      The next problem after that is that it cannot find the header files. For all I know, that may be the fault of the way MySQL is installed on Mac, or even the way that I installed it (although I did nothing special).

      I got both suggestions out of another thread on this forum after running into these problems, but I thought a discrete post with "Mac" in the subject would be more expedient.

      If the setup could be rigged to look for /usr/local/mysql in the event of failure then I believe it would all be automatic.

      -Chuck

       
      • Andy Dustman

        Andy Dustman - 2007-01-24

        Well, if it can't find mysql_config, it won't find anything else by default either (headers or libraries). OTOH, if it can find mysql_config, you shouldn't have to modify site.cfg, because it should find everything else. If you can't find mysql_config or the headers, you're pretty screwed.

        I happen to be looking at a MySQL-4;1.8 installation on Mac OS X and mysql_config is in /usr/local/mysql/bin, and running it gives sensible output. However, there are no Python development headers installed, so I can't test any further.

        running build
        running build_py
        copying MySQLdb/release.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.3/MySQLdb
        running build_ext
        building '_mysql' extension
        gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-c
        ommon -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/mysql/incl
        ude -I/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3
        -c _mysql.c -o build/temp.darwin-7.9.0-Power_Macintosh-2.3/_mysql.o -DBIG_TABLE
        S -Dversion_info=(1,2,2,'beta',2) -Dversion=1.2.2b2
        In file included from _mysql.c:29:
        pymemcompat.h:10:20: Python.h: No such file or directory
        _mysql.c:30:26: structmember.h: No such file or directory
        ...

        (the rest is irrelevant)

         
    • Chuck Esterbrook

      I mentioned "Python 2.5" in my post, but did not explicitly state that I'm not using the default Python that came with the Mac. At some eariler date, I obtained Python 2.5 from visiting python.org.

      So were you running the Python that ships with the Mac, or the latest production release (2.5)?

       
      • Andy Dustman

        Andy Dustman - 2007-01-25

        It was 2.3, and I think the stock version was 2.2.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.