Home > Database > Mysql Tutorial > How to Successfully Install MySQLdb on macOS?

How to Successfully Install MySQLdb on macOS?

Susan Sarandon
Release: 2024-12-01 21:47:12
Original
605 people have browsed it

How to Successfully Install MySQLdb on macOS?

How to Install MySQLdb on Mac OS X

MySQLdb is a Python data access library that enables interaction with MySQL databases. Installing MySQLdb on Mac OS X requires a specific set of steps to ensure compatibility with the system's environment.

Preparation

Before proceeding with the installation, verify that MySQL, Python, and GCC are installed on your Mac.

Installation Steps

  1. Download the latest MySQL for Python adapter from SourceForge.
  2. Extract the downloaded package.
  3. Clean the package using the command: sudo python setup.py clean.
  4. Remove the directory under MySQL-python-1.2.2/build/* and the egg under Users/$USER/.python-eggs.
  5. Create a symbolic link under lib to point to a sub-directory called mysql: sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql.
  6. Edit setup_posix.py and change mysql_config.path = "mysql_config" to mysql_config.path = "/usr/local/mysql/bin/mysql_config".
  7. Rebuild the package: sudo python setup.py build.
  8. Install the package: sudo python setup.py install.
  9. Test the installation by importing MySQLdb.

Additional Troubleshooting

If you encounter an error related to libmysqlclient.18.dylib being missing, create a symbolic link: sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib.

To resolve the warning about _mysql being already imported, change the directory to the parent of the build directory.

Python 3 Users

For Python 3, install the necessary libraries using: conda install mysqlclient. This will install mysqlclient, mysql-connector, and llvmdev.

The above is the detailed content of How to Successfully Install MySQLdb on macOS?. 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