Home >Database >Mysql Tutorial >How to Successfully Install MySQLdb on Mac OS X?

How to Successfully Install MySQLdb on Mac OS X?

Linda Hamilton
Linda HamiltonOriginal
2024-12-13 10:54:14528browse

How to Successfully Install MySQLdb on Mac OS X?

Installing MySQLdb on Mac OS X

Background:
Many users encounter difficulties installing MySQLdb on Mac OS X due to the conflicting bit versions of Python and MySQL.

Python Compatibility and MySQL Bit-Depth:
Ensure that you have installed the 32-bit version of MySQL, as Mac OS X comes pre-installed with a 32-bit Python version.

Steps to Install MySQLdb:

Step 1:
Obtain the MySQL for Python adapter from SourceForge.

Step 2:
Extract and clean the downloaded package:

tar xzvf MySQL-python-1.2.2.tar.gz
sudo python setup.py clean

Additional Steps:

  • Remove the contents of MySQL-python-1.2.2/build/* and the egg in Users/$USER/.python-eggs.
  • Skip editing _mysql.c, as the MySQLdb community has resolved this issue.
  • Create a symbolic link in lib to the mysql subdirectory:

    sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

Step 3:
Edit setup_posix.py and update the mysql_config path:

mysql_config.path = "mysql_config"

to

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Step 4:
Rebuild the package (ignore warnings):

sudo python setup.py build

Step 5:
Install the package:

sudo python setup.py install

Step 6:
Verify installation:

python
import MySQLdb

Step 7:
Create a symbolic link to libmysqlclient.18.dylib if necessary:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Step 8:
Start Python from outside of the build directory to avoid error messages.

The above is the detailed content of How to Successfully Install MySQLdb on Mac OS X?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn