I’m in the middle of moving OpenMRS’s web presence from a shared virtual machine to a new dedicated box.  The only trouble I ran into was with the mysql python module (again).

For posterity’s sake, I’m going to write my solution here.

easy_install mysql-python

I received this error when trying to install the MySQLdb-python module into python on centOS:

_mysql.c:2808: error: expected declaration specifiers before ‘init_mysql’
_mysql.c:2886: error: expected ‘{’ at end of input
error: Setup script exited with error: command ‘gcc’ failed with exit status 1

The fix I remembered.  I just had to install the python development packages:

yum install python-devel

I then had another very odd and strangely familiar error:

In file included from _mysql.c:35:
/usr/include/mysql/my_config.h:15:28: error: my_config_i386.h: No such file or directory
error: command ‘gcc’ failed with exit status 1

Googling around gave me nothing helpful…in fact the results looked strangely familiar as well.  I couldn’t remember the solution to this one though.

Eventually, I actually read the error message and realized that our new vm isn’t an x64 box.  For some reason there was a my_config_x64.h file in /usr/include/mysql but there wasn’t a my_config_i386.h.  Luckily, that file was present on the old server. Copying that file from /usr/include/mysql on the old box to the new was the cure.

Commenters have pointed out that sometimes “mysql-devel” needs to be installed as well

This is in the babble category tagged as , , ,


13 Responses

  1. Olivier Biot Says:

    Thanks for this information!

    For the record, apparently the MySQLDB Python package in CentOS has a Mixed Case name: “MySQL-python”. The command to install this module on CentOS is:

    $ yum install MySQL-python

    Hope this helps!


  2. Evlilik Sitesi Says:

    Awesome awesome post!!!

    I’ve been trying to install mysqldb for the last hour on my centos box and had countless errors before I read the comment on this post. I had no clue I could yum MySQL-python.

    It worked like a charm. Thanks Olivier and eflow!

  3. Elchin J Says:

    Thanks Olivier! I would never imagine that the name of MySQLdb api in CentOS is like MySQL-python. It solved my problem! Great!

  4. kadimi Says:

    I was getting similar error, Installing python-devel fixed it for me.


  5. vinh Says:

    I had installed MySQL-python on using
    $ yum install MySQL-python
    but when i used command
    import MySQLdb. it still not library in my machine
    i use Linux CentOS and using x86_64
    Please help me by send email to me:
    thanks so much

  6. Ben Says:

    Make sure you have installed python-devel (as the blog post says)

  7. DDevine Says:

    You may also have to install mysql-devel — this was my issue (on CentOS 5.5).

  8. Ram Indukuri Says:

    This is the perfect way to install MySQLdb on Cent OS
    $ yum install MySQL-python

    It worked like a charm. Tahnk you very much

  9. [Python] MySQLdb???????? | Kirishiki Studios Says:

    […] ??? Python MySQLdb install guide for cPanel/centOS « all things L337 Installation troubles with MySQLdb-python […]

  10. Kelson Says:

    You may also get this error if you forgot to install python-dev
    sudo apt-get install python-dev

  11. Hartley Says:

    As other’s mentioned, this post + Oliver’s comment about the package name being mixed case ended my wild goose chase. Thanks!!

  12. noobie2 Says:

    I needed to install mysql-python to an alternate python directory but when I did “/opt/python27/bin/easy_install mysql-python” I got the following error:
    my_config.h: No such file or directory
    mysql.h: No such file or directory
    Doing a “yum install mysql-devel” solved my issue. Thanks eflow and DDevine.

  13. Pankaj Goyal Says:

    in my case mysql-devel package was missing.

    # yum install mysql-devel

    # easy_install mysql-python
    Searching for mysql-python
    Reading http://pypi.python.org/simple/mysql-python/
    Reading http://sourceforge.net/projects/mysql-python/
    Reading http://sourceforge.net/projects/mysql-python
    Best match: MySQL-python 1.2.3
    Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
    Processing MySQL-python-1.2.3.tar.gz
    Running MySQL-python-1.2.3/setup.py -q bdist_egg –dist-dir /tmp/easy_install-wGwVh6/MySQL-python-1.2.3/egg-dist-tmp-RaxY1T
    warning: no files found matching ‘MANIFEST’
    warning: no files found matching ‘ChangeLog’
    warning: no files found matching ‘GPL’
    zip_safe flag not set; analyzing archive contents…
    Adding MySQL-python 1.2.3 to easy-install.pth file

    Installed /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg
    Processing dependencies for mysql-python
    Finished processing dependencies for mysql-python

Leave a Comment

Your comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.