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:
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!