Take the 2-minute tour ×

I installed the mysqldb for python on mac os x, but it gives me the following error:

Traceback (most recent call last):
  File "build/bdist.macosx-10.6-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_mysql)

How can I solve this issue?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

This is most likely due to a mismatch in architectures between the Python you are using, the MySQLdb adapter you installed, and the MySQL client libraries you have installed. They all need to have at least one common architecture and execute in that architecture. You may have a 32-bit-only Python and a 64-bit-only MySQL client library or vice versa. Make sure they match.

Unless you need the Python you are using, I strongly suggest installing a complete solution from a third-party package manager. For example, if you install the MacPorts base, you can then install everything you need (Python 2.7, MySQLdb, MySQL client library, and all dependencies) with one command:

sudo port install py27-mysql
share|improve this answer
Thanks works like a charm. :) –  user1799469 Nov 5 '12 at 10:24
add comment

Your Answer


