Install mysqldb and EnvironmentError on macos: mysql

Source: Internet
Author: User
$ Sudopythonsetup. pyclean $ sudopythonsetup. pybuild $ sudopythonsetup. pyinstall $ exportDYLD_LIBRARY_PATHusrlocalmysqllib: $ DYLD_LIBRARY_PATH $ your-packagesMySQL_python-1.2.3-py2.7-m

$ Sudo python setup. py clean $ sudo python setup. py build $ sudo python setup. py install $ export DYLD_LIBRARY_PATH =/usr/local/mysql/lib: $ DYLD_LIBRARY_PATH $ python import MySQLdb/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-m

$ Sudo python setup. py clean

$ Sudo python setup. py build

$ Sudo python setup. py install

$Export DYLD_LIBRARY_PATH =/usr/local/mysql/lib: $ DYLD_LIBRARY_PATH

$ Python

>>> Import MySQLdb
/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/_ mysql. py: 3: UserWarning: Module _ mysql was already imported from/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/_ mysql. pyc, but/Users/***/Downloads/MySQL-python-1.2.3 is being added to sys. path

>>> Conn = MySQLdb. connect (host = "localhost", user = "root", passwd = "root", db = "mysql ")
>>> Cursor = conn. cursor ()
>>> SQL = "select * from user"
>>> Cursor.exe cute (SQL)
7L
>>> Row = cursor. fetchone ()
>>> Print row
('Localhost', 'root', '* 81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 'y ', 'y ', 'y ', 'y', '', 0L, 0L, 0L, 0L ,'','')

The mysql. user table information can be read, indicating that mysqldb has been installed successfully.

Or modify the bash_profile file.

PATH="/usr/local/mysql/bin:${PATH}"export PATHexport DYLD_LIBRARY_PATH=/usr/local/mysql/lib/export VERSIONER_PYTHON_PREFER_64_BIT=yesexport VERSIONER_PYTHON_PREFER_32_BIT=no

Reference: http://stackoverflow.com/questions/1465846/install-mysqldb-on-snow-leopard/6537345#6537345

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.