How to install python mysqldb module in windows, pythonmysqldb

Source: Internet
Author: User

How to install python mysqldb module in windows, pythonmysqldb

The reason for writing this log is that the installation process is a bit abusive. Currently, this article is intended for installing mysqldb on windows. Install the mysqldb module of python. First, find some official websites to download it: https://pypi.python.org/pypi/mysql-python. After the download, cmd enters the MySQL-python-1.2.3 folder, according to the general execution of python setup. py install command to install this module, then the error is reported:

This error is obvious, print

Before Running python, determine which versions of mysqldb support python. Parts are as follows:

Mysql-python1.2.5 is the latest version, which supports mysql3.23-5.5, python2.4-2.7 and does not support the python3 series. During installation, python in the current system is 3.7.11. When uninstalling python, an error is returned:

There is a problem with this windows installer package. A programe run as part of the setupdid not finish as expected. Contact your support personnel or package vendor.

It is estimated that this problem may be caused by file defects, so I tried some solutions on the Internet:

Method 1: run the installer again, select repair, and uninstall it after the fix. (Result: useless. Another network exception error is reported during repair)
Method 2: Install python of another version and uninstall python 3.7.11)
Method 3: delete the registry information or use Your Unin-staller! Force Delete python3.7.11. (result: the deletion is successful,

Ps: http://wenku.baidu.com/link? Url = dujEO65nXySNvwUyDJVR5kmbrlcqp7WsvhLFGN_7L5q-58EoVjyw4DjiTS_J5PomPzgvdG69uulXDI8TbMgJlXk9Y-ayHs8qOD3Z3AomBU7 with product registration in the Link)

Or this article: http://www.bkjia.com/softjc/500307.html

The above three solutions only provide the third most violent solution to solve my problem. Some netizens in the first two solutions can use them and solve the problem after the operation. After uninstalling a later version of python, we finally installed a later version of python.

Install mysqldb, and then report an error: the C language compilation environment is missing, and a VC environment needs to be downloaded. This is actually very good, the error prompt in the original download link (forgot, sorry) https://www.microsoft.com/en-us/download/confirmation.aspx? Id = 44266. If you download VCForPython27.msi, this error is not reported. But another error is reported. (Forget again), and then feel it is necessary to view the readme under the MySQL-python-1.2.3 folder, which will generally record how to install and how to use. Some important information about windows Installation is translated as follows:

Windows. But if someone provides me with a Windows package, I will make it available. Do not ask me for help on Windows because I cannot help you. Generally, run setup. py is similar to: C: \...> python setup. py install C: \...> python setup. the following example of py bdist_wininst should build a Windows installation package if you have the correct tool. In any case, you must have a C compiler. In addition, you must set an environment variable (mysqlroot), which is the path for MySQL installation. Theoretically, it may obtain this information from the registry, but as I said, I am not Windows, but I will accept the patch. On Windows, you must edit site. cfg because MySQL package does not contain mysql_config.

Then I started to install mysql silently and went to the official website for a 5.5.7 version. When installing and verifying the connection to the database, I always reported an ERROR: ERROR 1045 (28000 ): access denied for user 'mysql' @ 'localhost' (using password: NO)

Add skip-grant-tables to my. ini in the installation folder under Baidu.

[mysqld]skip-grant-tables# The TCP/IP Port the MySQL Server will listen onport=3306

Then I can connect to the database and access the database. I think it should be okay. However, when installing the database, I reported an error:

E:\Code\Python\mysql>setup.py install Traceback (most recent call last):  File "E:\Code\Python\mysql\setup.py", line 15, in <module>  metadata, options = get_config()  File "E:\Code\Python\mysql\setup_windows.py", line 7, in get_config  serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key']) WindowsError: [Error 2]

Feasible Solution: Open setup_windows.py, comment out the two lines of code for registry operation, and add a line of code:

# ServerKey = _ winreg. openKey (_ winreg. HKEY_LOCAL_MACHINE, options ['registry _ key']) # mysql_root, dummy = _ winreg. queryValueEx (serverKey, 'location') mysql_root = "C: \ Program Files \ MySQL Server 5.5" # MySQL directory

Then install the SDK and report the following error:

Work und: Download MySQL Connector (Address: http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-win32.msi/from/http://ftp.jaist.ac.jp/pub/mysql/), and then modify the setup_windows.py code:

# ServerKey = _ winreg. openKey (_ winreg. HKEY_LOCAL_MACHINE, options ['registry _ key']) # mysql_root, dummy = _ winreg. queryValueEx (serverKey, 'location') mysql_root = "C: \ Program Files \ MySQL Connector C 6.0.2" # MySQL Connector C 6.0.2 directory

Then execute the installation. Oh, my God, the installation is successful.

import MySQLdbif __name__ == "__main__": test= MySQLdb.connect("localhost","root","root1234","mysql" ) cur = test.cursor() cur.execute('show databases;') for data in cur.fetchall():  print data

The output is as follows:

D:\Python27\python.exe D:/untitled/mysql_test.py('information_schema',)('mysql',)('performance_schema',)('test',)Process finished with exit code 0

I installed a third-party library before I learned RF, but I have never been so abusive. Maybe I was using a lower version of python, and there was a compilation environment for various programs on the machine, however, a problem is exposed, that is, there is no common method for quick installation during third-party library installation. Based on the experience of dog blood, we will make the following summary:
1. Check the read me in the installation file and some instructions on the download page before installation (generally, the author will write the installation manual and test documents, regardless of the operating system type, we will introduce it more or less ).

2. determine which version of python is supported by the python third-party library. Currently, python2.7.11 is quite good.

3. Determine the other environments and dependent software required for third-party library installation.

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.