天天看點

MySQLDB子產品安裝--Mac系統

一、首先在系統中安裝mysql

安裝包路徑

http://www.mysql.com/downloads/

MySQL Community Edition

 (GPL)

Community (GPL) Downloads

  • MySQL Community Server (GPL)

    (Current Generally Available Release: 5.7.16)MySQL Community Server is the world's most popular open source database.DOWNLOAD

MySQLDB子產品安裝--Mac系統

選擇最下面一個下載下傳

下載下傳後直接點選,進行安即可

安裝後

wulilideMacBook-Pro:bin root# mysql --version

mysql command not foud

wulilideMacBook-Pro:bin root# ln -fs /usr/local/mysql/bin/mysql mysql

wulilideMacBook-Pro:bin root# /usr/local/mysql/support-files/mysql.server start

Starting MySQL

. SUCCESS! 

wulilideMacBook-Pro:bin root# /usr/local/mysql/support-files/mysql.server sop  

Usage: mysql.server  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]

wulilideMacBook-Pro:bin root# /usr/local/mysql/support-files/mysql.server stop

Shutting down MySQL

.. SUCCESS! 

安裝後發現報錯

Can\'t connect to local MySQL server through socket \'/tmp/mysql.sock\' 

百度了很多,最終在我的電腦的處理方法是

chmod 777 /tmp

修改了權限之後,就出現了.sock這個檔案,啟動也不報錯,python使用也正常了。

2、安裝mysql-python

使用pip安裝是沒有辦法修改安裝包中的檔案的,,是會一直報錯的

wulilideMacBook-Pro:~ root# pip install MySQL-python

Collecting MySQL-python

  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. (read timeout=15)",)': /simple/mysql-python/

  Using cached MySQL-python-1.2.5.zip

    Complete output from command python setup.py egg_info:

    sh: mysql_config: command not found

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/private/tmp/pip-build-8VXXdd/MySQL-python/setup.py", line 17, in <module>

        metadata, options = get_config()

      File "setup_posix.py", line 43, in get_config

        libs = mysql_config("libs_r")

      File "setup_posix.py", line 25, in mysql_config

        raise EnvironmentError("%s not found" % (mysql_config.path,))

    EnvironmentError: mysql_config not found

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-8VXXdd/MySQL-python/

隻好選擇源碼包安裝

下載下傳源碼包

https://pypi.python.org/pypi/MySQL-python/1.2.5

選擇源碼包下載下傳,解壓,

修改解壓後的配置檔案

wulilideMacBook-Pro:MySQL-python-1.2.5 root# pwd

/Users/wulili/Downloads/MySQL-python-1.2.5

wulilideMacBook-Pro:MySQL-python-1.2.5 root# ls -l

total 336

-rw-rw-rw-@  1 wulili  staff  18092 Oct  8  2012 GPL-2.0

-rw-rw-rw-@  1 wulili  staff   5687 Jan  1  2013 HISTORY

-rw-rw-rw-@  1 wulili  staff   6636 Oct  8  2012 INSTALL

-rw-rw-rw-@  1 wulili  staff    309 Jan  2  2014 MANIFEST.in

drwxr-xr-x@  6 wulili  staff    204 Nov  4 18:34 MySQL_python.egg-info

drwxr-xr-x   9 wulili  staff    306 Nov  4 18:34 MySQLdb

-rw-rw-rw-@  1 wulili  staff   1689 Jan  2  2014 PKG-INFO

-rw-rw-rw-@  1 wulili  staff   1266 Oct  4  2012 README.md

-rw-rw-rw-@  1 wulili  staff  84709 Jan  2  2014 _mysql.c

-rw-rw-rw-@  1 wulili  staff   2352 Oct  8  2012 _mysql_exceptions.py

drwxr-xr-x  12 wulili  staff    408 Nov  4 18:34 doc

-rw-rw-rw-@  1 wulili  staff   2039 Jan  2  2014 metadata.cfg

-rw-rw-rw-@  1 wulili  staff   3203 Oct  8  2012 pymemcompat.h

-rw-rw-rw-@  1 wulili  staff    398 Jan  2  2014 setup.cfg

-rw-rw-rw-@  1 wulili  staff    609 Jan  2  2014 setup.py

-rw-rw-rw-@  1 wulili  staff   1088 Oct  8  2012 setup_common.py

-rw-rw-rw-@  1 wulili  staff   3392 Jan  2  2014 setup_posix.py

-rw-rw-rw-@  1 wulili  staff   1334 Oct  8  2012 setup_windows.py

-rw-rw-rw-@  1 wulili  staff    665 Oct  8  2012 site.cfg

drwxr-xr-x   8 wulili  staff    272 Nov  4 18:34 tests

wulilideMacBook-Pro:MySQL-python-1.2.5 root# vim setup_posix.py 

            raise EnvironmentError("%s not found" % (mysql_config.path,))

    return data

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

def get_config():

    from setup_common import get_metadata_and_options, enabled, create_release_file

wulilideMacBook-Pro:MySQL-python-1.2.5 root# vim site.cfg 

# The path to mysql_config.

# Only use this if mysql_config is not on your PATH, or you have some weird

# setup that requires it.

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

# http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-windows-pip

# Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build.

connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2

修改好後安裝即可

wulilideMacBook-Pro:MySQL-python-1.2.5 root# python setup.py install

wulilideMacBook-Pro:MySQL-python-1.2.5 root# python

Python 2.7.10 (default, Oct 23 2015, 19:19:21) 

[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import MySQLdb

繼續閱讀