Use Python's MySQLdb module in Win7, win7mysqldb

Source: Internet
Author: User

Use Python's MySQLdb module in Win7, win7mysqldb
Overview:

In Linux, the processing of this part is good, but it is a little troublesome on Windows. The trouble is not in the installation process, but may cause some problems during the installation process.


Step: 1. Install the MySQLdb Module

We download the corresponding MySQLdb version file online, for example, my is MySQL-python-1.2.3.win-amd64-py2.7. This file is an exe file. Click Run.


2. Solve python version 2.7 required, which was not found in the registry error


When I download mysql-python-1.2.3.win-amd64-py2.7.exe for installation, the program reports the following error message:



Cause analysis:

Win7 is 64-bit. When installing python, if you select only the current user, the above issues will not occur. If you select all users, use the above methods to solve it.


Solution:

1. Copy the following code and save it to register. py:

## 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 necessaryversion = 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()


2. Run register. py.


3. solve the problem that the DLL load failed: % 1 is not a valid Win32 application.


The reason for the above problem is that our Python and MySQLdb versions do not match. My problem is that Python is 32-bit, while MySQLdb is 64-bit.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger. Http://blog.csdn.net/lemon_tree12138

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.