Error reporting and solution during MySQLdb installation

Source: Internet
Author: User
This article mainly introduces the problems and solutions for installing pythonMySQLdb in Windows. if you need it, refer to the following article to introduce the problems and solutions for installing python MySQLdb in Windows, for more information, see

Title: because of work requirements, setting up the MySQL + Python + MySQLdb environment on CentOS, I am used to the operating habits of Windows systems, and I am not very familiar with character-only OS for the time being, we hope to build a similar environment on Windows for development. The following describes how to compile MySQLdb in Windows. I recently found a MySQLdb Windows installation package on the Internet, it will be more convenient to use, address: http://www.codegood.com/archives/4

Or

Mysql-connector-python is a dedicated python driver provided by the MySQL official website. it is easy to use. There are many program instances in the file for your reference.

The process of manually compiling MySQLdb is as follows:

The following lists the software used above:

MySQL-www.mysql.com/ <个人使用的mysql的版本:mysql-essential-5.1.53-win32.msi,也许您下载的时候已经有新的版本了。>

Python-www.python.org/ <个人使用的python版本:python-2.6.6.msi>

MySQLdb-sourceforge.net/projects/mysql-python/ <个人使用的mysqldb版本:mysql-python-1.2.3.tar.gz>

1. install MySQL, select Custom, and check "C Include Files/Lib Files". if Typical is used, the problem may occur (1 ), the subsequent configurations are basically the default options, except for the additional check box "add to System PATH" (Include Bin Directory in Windows PATH. If you are not very clear about installing MySQL, you can search from the Internet, related articles a lot, as follows: http://rangyang163.blog.163.com/blog/static/37743758200881203744469/

2. install Python, which is basically the default option, but slightly changed the installation path. The default installation path of Python is "C:/Python26", which is changed to "C:/Program Files/Python26"

3. you must install setuptools before installing MySQLdb. Otherwise, a compilation error may occur.

Setuptools-http://pypi.python.org/pypi/setuptools <将滚动条向下拖,很快,就可以看到一串,个人使用的是:setuptools-0.6c11.win32-py2.6.exe,这是因为我使用的python版本是2.66>

Install this tool by default...

Now, we can start to install mysqldb. the tar.gz package we downloaded is the source code package, and there is no installation program in it. we need to compile the package before installing it. <其实只要看看readme就明白了。>

(1)extract mysql-python-1.2.3.tar.gz to the current directory, a MySQL-python-1.2.3 folder appears;

(2) WIN + R, open the Run dialog box, enter cmd, open the MS-DOS, enter the folder decompressed above; (the premise is that you have to understand what cd is the command :-)....)

(3) enter setup. py build to start compilation... <额外补充一点,在编译mysqldb时需要c编译器,如果已经安装了msvc,则直接编译即可。如果需要指定编译器,可以使用compiler开关。如--compiler=mingw32则使用gcc作为编译器,不过,前提是你需要安装相应的编译器,并配置好环境变量才行。>

I encountered the following problems during compilation:

1) problem: _ mysql. c (34): fatal error C1083: Cannot open include file: 'config-win. h': No such file or directory
Error: command '"C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN/cl.exe" 'failed' with exit status 2

Cause: the C language library is not installed when MySQL is installed.

Solution: run the MySQL installation program again, select Modify, select "C Include Files/Lib Files", and install it.

2) problem: Traceback (most recent call last ):
File "setup. py", line 15, in
Metadata, options = get_config ()
File "C:/MySQL-python-1.2.3/setup_windows.py", line 7, in get_config
ServerKey = _ winreg. OpenKey (_ winreg. HKEY_LOCAL_MACHINE, options ['registry _ key'])
WindowsError: [Error 2] The system cannot find the file specified

Cause: MySQL for python 1.2.3 is still searching for MySQL

Solution: 1. open the site. cfg file in the directory and change the last line to "registry_key = SOFTWARE/MySQL AB/MySQL Server 5.1"
2. open the setup_windows.py file and modify the seventh behavior "serverKey = _ winreg. OpenKey (_ winreg. HKEY_LOCAL_MACHINE, 'software/MySQL AB/MySQL Server 100 ')"

3) problem: build/temp. win32-2.7/Release/_ mysql. pyd. manifest: general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Error: command 'mt.exe 'failed with exit status 31

Cause: The path changes?

Solution: open "your PYTHON installation directory/Lib/distutils/msvc9compiler. in the "py" file, find the code "ld_args.append ('/MANIFESTFILE:' + temp_manifest)" and change it to "ld_args.append ('/MANIFEST ')"

(4) After compilation, enter setup. py install!

You can enter the following command in the DOS environment for testing:

C:/Users/Michael>pythonPython 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] onwin32Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>>

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.