zoukankan      html  css  js  c++  java
  • Mac安装mysqldb

    1. 一、 安装mysql

    (一)下载地址 https://pan.baidu.com/s/1slw50LZ 

    安装成功后,在系统偏好设置里有MySQL图标,可以启动或关闭MySQL

    1. 二、 Mysql root用户密码重置

    如果安装时生成的默认密码不可用,可以重置密码,步骤如下:

    1、停止mysql服务 

    系统偏好设置 > MySQL > 停止。

    2、启动mysqld_safe ,跳过启动授权表。启动时加上skip-grant-tables参数目的是在启动mysql时不启动grant-tables,授权表。这样就可以修改root的密码了。

     # ./mysqld_safe --skip-grant-tables &

    3、登录mysql,并修改密码

    # mysql -uroot -p      ----要求输入密码时,直接回车即可。

    > use mysql;

    > update mysql.user set authentication_string=password('新密码') where user='root' and Host ='localhost';    ---将root密码设置为123456 

    >  flush privileges;

    > quit

    4、杀死mysqld_safe进程,并重启mysqld

    # kill -9  mysqld_safe进程id 

    # service mysqld start

    # mysql -uroot -p     (输入新设置的密码即可)

    5、连接本地数据库

    Hostname: 127.0.0.1  Port: 3306  Username: root

    1. 三、 安装mysql-python

    1、修改OS X环境变量

    打开终端,在终端中使用vim打开“~/.bash_profile”,如果没有安装vim,那就显示隐藏文件用文本编辑器打开,具体操作这里就不复述了。在.bash_profile中添加以下内容: 

    PATH="/usr/local/mysql/bin:${PATH}" 

    export PATH 

    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ 

    export VERSIONER_PYTHON_PREFER_64_BIT=no 

    export VERSIONER_PYTHON_PREFER_32_BIT=yes 

    其中 VERSIONER_PYTHON_PREFER_64_BIT和VERSIONER_PYTHON_PREFER_64_BIT根据自己安装的MySQL进行选择。 

    保存后关闭终端。

    2、安装mysql-python

    打开终端,执行 pip install MySQL-python 

    3、验证成功

    在python交互模式下执行 import MySQLdb,import没有问题,即为安装成功

    四、 Mac上eclipse安装mysqldb

    mac eclipse PyDev导入 mysqldb(解决Unresolved import: MySQLdb错误):

    在交互模式下输入命令:

    >>> import MySQLdb

    >>> print MySQLdb.__file__

    得到结果如下:

    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQLdb/__init__.pyc

    Eclipse-> Preferences -> PyDev -> Interpreters -> Python interpreter -> Libraries -> New Folder  添加上面的/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 路径

    重启eclipse

    执行以下命令

    欢迎关注光荣之路喜马拉雅电台:http://m.ximalaya.com/weizhubo/44966139

    640.jpg

  • 相关阅读:
    AGC037F Counting of Subarrays
    AGC025F Addition and Andition
    CF506C Mr. Kitayuta vs. Bamboos
    AGC032D Rotation Sort
    ARC101F Robots and Exits
    AGC032E Modulo Pairing
    CF559E Gerald and Path
    CF685C Optimal Point
    聊聊Mysql索引和redis跳表
    什么是线程安全
  • 原文地址:https://www.cnblogs.com/tom-gao/p/5838950.html
Copyright © 2011-2022 走看看