Install MYSQLDB in OS X (that is, Mysql-python package)

Source: Internet
Author: User
Tags mysql

Installation environment: OS X operating system, Python 2.7.3.

MySQLdb is actually included in the Mysql-python package, so whether you download it or search in Pip, you should search for Mysql-python.

The following describes the two common installation methods for MYSQLDB, download installation or PIP installation Mysql-python. 

Download MySQLdb

SourceForge can download Mysql-python-1.2.4b4.tar, unzip after downloading, and then execute the following command in the terminal terminal:

new-host-3:~ ifantastic$ CD/USERS/IFANTASTIC/DOWNLOADS/MYSQL-PYTHON-1.2.4B4

NEW-HOST-3:MYSQL-PYTHON-1.2.4B4 ifantastic$ python setup.py install

Install MYSQLDB using PIP

To execute in a terminal:

new-host-3:~ ifantastic$ pip Install Mysql-python

Whether it's an online installation or a download installation, you may experience the first error message:

Environmenterror:mysql_config not found

It is recommended that you use PIP installation because the version I downloaded from SourceForge is not as new as the PIP. If you want to upgrade the Mysql-python version, you can use the following command:

$ easy_install Mysql-python--upgrade

[Note] If you do not follow the instructions below to resolve the installation error, the upgrade will fail for the same reason.

Resolve Mysql_config not found error

When you install the Mac version of MySQL by default, the Mysql_config file is generated in the/usr/local/mysql/bin directory.

So the solution to download the installation is: Find the Site.cfg file in the Mysql-python installation package, open it, and find the following:

# The path to Mysql_config.

# only use this if mysql_config isn't on your PATH, or you have some weird

# setup that requires it.

# mysql_config =/usr/local/bin/mysql_config

Remove the last sentence from the first well and modify it to:

Mysql_config =/usr/local/mysql/bin/mysql_config

Then execute:

$ python setup.py Install

Generally, installation can be completed at this time, but there are still problems, which will continue to be described below.

There is no way to modify the Site.cfg file with the PIP installation, so you can fix the system environment variable of OS X to resolve the error that cannot find the mysql_config.

Modify the OS X environment variable: Open the terminal, use Vim in the terminal to open "~/.bash_profile", if not install VIM, that show hidden file opens with the text editor, the concrete operation here is no longer stated. Add the following in. Bash_profile:

Path= "/usr/local/mysql/bin:${path}"

Export PATH

Export dyld_library_path=/usr/local/mysql/lib/

Export Versioner_python_prefer_64_bit=no

Export Versioner_python_prefer_32_bit=yes

Where Versioner_python_prefer_64_bit and Versioner_python_prefer_64_bit are selected according to their installed MySQL.

In addition to providing a mysql_config solution (I did not validate) for a PIP installation, enter the following command in the terminal:

$ sudo ln-s/usr/local/mysql/bin/*/usr/bin

Well, here, the Mysql-python package should be basically smoothly installed.

Resolve Reason:image not found error

After installing the Mysql-python package, let us import mysqldb, at this time an error, the last line of the error is written reason:image not found.

The workaround is to execute at the terminal:

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

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

After restarting idle, successfully import MySQLdb.

PS: Using PIP to install Mysql-python in Ubuntu will also appear mysql_config no found error prompts, it is recommended to use sudo apt-get install python-mysqldb to install, This allows the installation to succeed directly.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/other/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.