8

A colleague got this error message when trying to use MySQLdb from Django:

[...]
ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: 
Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2): 
Symbol not found: _mysql_affected_rows 
Referenced from: /Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so Expected in: dynamic lookup

He's using OS X 10.5, Python 2.5 (arriving with OS X), MySQL 5.1 & MySQLdb 1.2.3c1.

Any idea how to attack this?

Olli
  • 1,231
  • 15
  • 31

6 Answers6

6

It might be best if you install mysql and it's Python bindings from scratch, I use the following steps whenever I need MySQLdb on OS X 10.4 or 10.5:

  1. Install MySQL for your system, the dmg installer should be sufficient

  2. The default location of MySQL will be somewhere around: /usr/local/mysql-5.0.45-osx10.4-i686. From /usr/local/mysql/lib, create a soft link:

    ln -s ../../mysql-5.0.45-osx10.4-i686/lib mysql

  3. Download the MySQLdb source and unpack it

  4. Edit the file site.cfg under your unpacked MySQLdb directory, comment out the registry_key and set mysql_config to:

    mysql_config = /usr/local/mysql-5.0.45-osx10.4-i686/bin/mysql_config

  5. Carry on with the regular Python packages build from within MySQLdb directory:

    sudo python setup.py install

  6. If everything is fine above, test MySQLdb in a new terminal:

    python -c "import MySQLdb"

The above should return nothing if successful. The above example shows OS 10.4 and MySQL 5.0, substitute them with the your proper tools version.

Thierry Lam
  • 45,304
  • 42
  • 117
  • 144
  • The mysql 10.6 dmg is not out yet, once it's released, give it another whirl. – Thierry Lam Aug 31 '09 at 18:10
  • 1
    Thanks for this solution. It nearly worked on my system (OSX 10.7). However I need to add the **-arch x86_64** flag to the compiler and linker flags. This is how I need to change the **setup_posix.py** from the MySQLdb-python package: in the section where the `ext_options` are build I changed `extra_compile_args = extra_compile_args` to `extra_compile_args = extra_compile_args + ['-arch',"x86_64"]` and `extra_link_args = extra_link_args` to `extra_link_args = extra_link_args + ['-arch',"x86_64"]` – spassig Nov 30 '11 at 16:03
1

It was Complicated and hard but it worked on MacOSX Lion.

you will be using :

Xcode
Brew
Port
Pip

make sure that you have Xcode(4.X) installed , and your mac is configured to find the executables because it will be used by Macports during the process of installing mysql-python.

Make sure that Xcode Command line Tools are installed

start Xcode app >> preferences >> download >> Components tab >> Command Line Tools >> click install

run the following commands from the terminal.

xcodebuild -version

if you ran into this error

/usr/bin/xcodebuild -version Error: No developer directory found at /Developer

Try to Run

/usr/bin/xcode-select
this will update the developer directory path.

Then you need to switch manually to the new Xcode install dir in /Applications:

sudo /usr/bin/xcode-select -switch /Applications/Xcode.app

Ref

Uninstall mysql [Backup you data before doing so !].

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*

Use brew to install Mysql again:

brew install mysql

you might run into this error.

Error: Cannot write to /usr/local/Cellar

the fix.

you should be ready to go now.

sudo port install py27-mysql

pip install mysql-python

python -c "import MySQLdb"

if you don't see any errors MySQLdb is installed.

Community
  • 1
  • 1
Ayed
  • 373
  • 5
  • 17
0

Yes, the MySQLDb egg was compiled against a different version of libmysqlclient than the version present in the system. You need to either get a proper egg (uninstalling the previous) or to build MySQLDb from scratch to compile it against the library present in your system.

I don't know why but I think your colleague might be interested in this question:

Configuring Django to use remote mysql server?

Community
  • 1
  • 1
Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
0

Try to run:

easy_install -U distribute
pip install --upgrade mysql-python

Note: If you have any errors of missing symbols while compiling, you need to have mysql development libs to compile it.

On Linux it's easy to install it:

sudo apt-get install mysql-devel

or:

sudo yum install mysql-devel

On Mac you probably need to download MySQL Connector and then you may have to pass in a --with-mysql-libs option to point to the directory when the C libraries are unpacked to. Or you can try to put the libraries in the default directory: /usr/lib64/mysql

kenorb
  • 155,785
  • 88
  • 678
  • 743
0

I had trouble with Thierry's solution on 32-bit Python (2.6.5) on OS X 10.6.

Upgrading to Python 2.7 64-bit version fixed the problem for me.

Aneil Mallavarapu
  • 3,485
  • 5
  • 37
  • 41
-1
sudo apt-get install python-mysqldb

make sure it should installed properly

or you can use another alternative like easy_install

user1614526
  • 474
  • 1
  • 4
  • 13