$ 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