The situation and solution of error encountered when installing MYSQLDB

Source: Internet
Author: User
This article mainly describes the Windows installation of Python MySQLdb encountered problems and solutions, the need for friends can refer to the following

Title: Because of the work required, in the CentOS build environment mysql+python+mysqldb, personal more accustomed to use the Windows system operating habits, on the pure character of the OS is not too accustomed to, so, hope to build a similar environment on the Windows system, for development. The following describes the process of compiling mysqldb in a Windows environment. Add: Recently found on the internet to a mysqldb Windows installation package, it will be more convenient to use, address: HTTP://WWW.CODEGOOD.COM/ARCHIVES/4

Mysql-connector-python is a specially connected Python driver that is available on the MySQL website and is easy to use. There are many examples of programs in the file for reference.

The process of compiling mysqldb manually is as follows:

Here are the download addresses for the software you need to use:

mysql-www.mysql.com/< personal use of MySQL version: Mysql-essential-5.1.53-win32.msi, maybe you have a new version of the download. >

python-www.python.org/< python version:python-2.6.6.msi> for personal use

mysqldb-sourceforge.net/projects/mysql-python/< personal use of MYSQLDB version:mysql-python-1.2.3.tar.gz>

1, install MySQL, select Custom, and then the "C Include files/lib Files" Check, if you use typical, then the problem (1), the following configuration is basically the default option, in addition to the additional "add to the System path" (Include This check box is checked in the Bin Directory in Windows PATH. If you are not very clear about the installation of MySQL, you can search from the Internet, related articles a lot

2, install Python, also basically the default option, just to change the installation path a little bit. The default installation path for Python is "c:/python26" and is used by individuals to change it to "C:/Program Files/python26"

3. You must install the setuptools before installing MYSQLDB, or there will be a compilation error.

Setuptools-http://pypi.python.org/pypi/setuptools < Drag the scroll bar down, and soon you'll see a list of download addresses, Personal use: Setuptools-0.6c11.win32-py2.6.exe, this is because the Python version I'm using is 2.66>

This tool can be installed by default ...

OK, you can formally start the installation of MYSQLDB, we downloaded this tar.gz is the source package, there is no installation program, need to compile, and then install. < In fact, just look at the Readme to understand. >

(1) Extract the mysql-python-1.2.3.tar.gz to the current directory, a mysql-python-1.2.3 folder will appear;

(2) Win+r, open the Run dialog, enter CMD, open MS-dos and go to the folder unzipped above, if you have to understand what the CD command:-) .... )

(3) Enter setup.py build to start compiling ...< additional, the C compiler is required when compiling mysqldb, and if MSVC is already installed, it can be compiled directly. If you need to specify a compiler, you can use the compiler switch. For example,--COMPILER=MINGW32 uses GCC as the compiler, but only if you need to install the appropriate compiler and configure the environment variables. >

I encountered the following issues during the compilation process:

1) Problem: _MYSQL.C: 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 was not installed when MySQL was installed.

Workaround: Re-run the MySQL installer, select Modify, check "C Include files/lib Files" and install.

2) Question: Traceback (most recent):
File "setup.py", line <module>
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

Reason: MySQL for Python 1.2.3 is still looking for MySQL5.0 version

Resolution: 1, open the directory under the Site.cfg file, modify the last behavior "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 5.1 ') "

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: path changed?

Workaround: Open the "Your Python installation directory/lib/distutils/msvc9compiler.py" file and find "Ld_args.append ('/manifestfile: ' + temp_manifest)" In this line of code, Change it to "ld_args.append ('/manifest ')"

(4) When the compilation is complete, you can enter the setup.py install, and now it's done!

You can test by entering the following command in a DOS environment:

C:/users/michael>pythonpython 2.6.6 (r266:84297, 18:46:32) [MSC v.1500 + bit (Intel)] Onwin32type "Help", "Copyright", "credits" or "license" for more information.>>> import mysqldb>>>

"Recommended"

1. Python Free video tutorial

2. Python meets data collection video tutorial

3. Python Learning Manual

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.