码迷,mamicode.com
首页 > 数据库 > 详细

MySQLDB模块安装--Mac系统

时间:2016-11-05 03:15:52      阅读:702      评论:0      收藏:0      [点我收藏+]

标签:community   mysql   

一、首先在系统中安装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 --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! 



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 

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

/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

>>> 

能导入成功说明安装好了

MySQLDB模块安装--Mac系统

标签:community   mysql   

原文地址:http://10983441.blog.51cto.com/10973441/1869613

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!