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

How to Successfully Install MySQLdb on Mac OS X?

Linda Hamilton
Release: 2024-12-13 10:54:14
Original
527 people have browsed it

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
Copy after login

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
    Copy after login

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

mysql_config.path = "mysql_config"
Copy after login

to

mysql_config.path = "/usr/local/mysql/bin/mysql_config"
Copy after login

Step 4:
Rebuild the package (ignore warnings):

sudo python setup.py build
Copy after login

Step 5:
Install the package:

sudo python setup.py install
Copy after login

Step 6:
Verify installation:

python
import MySQLdb
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template