python安装MySQLdb 遇到的问题汇总

因为对mysql相对熟悉一些,就准备用mysql来作为项目数据库,本以为安装也是手到擒来,没想到一安装都是各种报错,折腾一晚上才安装成功。做笔记以备忘。

情况一: 运行 pip install mysql-python 提示 Microsoft Visual C++ 9.0 is required

解决方案:前往:https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266 下载 VCForPython27.msi 程序,傻瓜式安装

 

情况二:下载 MySQL-python-1.2.5.win-amd64-py2.7.exe 安装mysql ,结果第一步就提示python 2.7 没有注册,但是我的确已经下载了,百度万能:

# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
 
import sys
 
from _winreg import *
 
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
 
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath
)
 
def RegisterPy():
    try:
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:
        try:
            reg = CreateKey(HKEY_CURRENT_USER, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print "*** Unable to register!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!"
 
if __name__ == "__main__":
    RegisterPy()

保存文件到桌面并命名为 Register.py, python 运行该文件,会提示已经注册

情景三,以为总算安装成功了mysql了嘛,没有,在 views.py 试着 import mysql模块:

from django.shortcuts import render_to_response
import datetime
import MySQLdb

def temp_test(request):
	now = datetime.datetime.now()
	return render_to_response('temp_test.html', locals())

又提示DLL 不是有效的Win32应用程序

解决方法:下载对应64位的pywin32

最后运行正常

 

/*********************************************************************************/

扩展:装了mysql后,再次启动phpstudy的时候,发现两者数据库之间发生了冲突,phpstudy的mysql无法启动,通过查找计算机运行的mysql的程序:

win+R---->regedit---->HKEY_LOCAL_MACHINE---->SYSTEM---->CurrentControlSet---->Services---->MySQL

把imagePath 对应的值改成phpstudy对应的mysql 下的 bin 目录下,重启,正常。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值