212121 发表于 2016-11-7 13:36:48

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


选择最下面一个下载
下载后直接点击,进行安即可
安装后
wulilideMacBook-Pro:bin root# mysql --versionmysql command not foud
wulilideMacBook-Pro:bin root# ln -fs /usr/local/mysql/bin/mysql mysqlwulilideMacBook-Pro:bin root# /usr/local/mysql/support-files/mysql.server startStarting MySQL. SUCCESS! wulilideMacBook-Pro:bin root# /usr/local/mysql/support-files/mysql.server sopUsage: mysql.server{start|stop|restart|reload|force-reload|status}[ MySQL server options ]wulilideMacBook-Pro:bin root# /usr/local/mysql/support-files/mysql.server stopShutting down MySQL.. SUCCESS!
2、安装mysql-python
使用pip安装是没有办法修改安装包中的文件的,,是会一直报错的
wulilideMacBook-Pro:~ root# pip install MySQL-pythonCollecting MySQL-pythonRetrying (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.5wulilideMacBook-Pro:MySQL-python-1.2.5 root# ls -ltotal 336-rw-rw-rw-@1 wulilistaff18092 Oct82012 GPL-2.0-rw-rw-rw-@1 wulilistaff   5687 Jan12013 HISTORY-rw-rw-rw-@1 wulilistaff   6636 Oct82012 INSTALL-rw-rw-rw-@1 wulilistaff    309 Jan22014 MANIFEST.indrwxr-xr-x@6 wulilistaff    204 Nov4 18:34 MySQL_python.egg-infodrwxr-xr-x   9 wulilistaff    306 Nov4 18:34 MySQLdb-rw-rw-rw-@1 wulilistaff   1689 Jan22014 PKG-INFO-rw-rw-rw-@1 wulilistaff   1266 Oct42012 README.md-rw-rw-rw-@1 wulilistaff84709 Jan22014 _mysql.c-rw-rw-rw-@1 wulilistaff   2352 Oct82012 _mysql_exceptions.pydrwxr-xr-x12 wulilistaff    408 Nov4 18:34 doc-rw-rw-rw-@1 wulilistaff   2039 Jan22014 metadata.cfg-rw-rw-rw-@1 wulilistaff   3203 Oct82012 pymemcompat.h-rw-rw-rw-@1 wulilistaff    398 Jan22014 setup.cfg-rw-rw-rw-@1 wulilistaff    609 Jan22014 setup.py-rw-rw-rw-@1 wulilistaff   1088 Oct82012 setup_common.py-rw-rw-rw-@1 wulilistaff   3392 Jan22014 setup_posix.py-rw-rw-rw-@1 wulilistaff   1334 Oct82012 setup_windows.py-rw-rw-rw-@1 wulilistaff    665 Oct82012 site.cfgdrwxr-xr-x   8 wulilistaff    272 Nov4 18:34 testswulilideMacBook-Pro:MySQL-python-1.2.5 root# vim setup_posix.py wulilideMacBook-Pro:MySQL-python-1.2.5 root# vim setup_posix.py
            raise EnvironmentError("%s not found" % (mysql_config.path,))    return datamysql_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# pythonPython 2.7.10 (default, Oct 23 2015, 19:19:21) on darwinType "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb/Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.11-intel.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.11-intel.egg/_mysql.pyc, but /Users/wulili/Downloads/MySQL-python-1.2.5 is being added to sys.path>>> 能导入成功说明安装好了
                   

页: [1]
查看完整版本: MySQLDB模块安装--Mac系统