search
HomeDatabaseMysql TutorialHow to install python's mysqldb module under windows

This article mainly introduces the installation method of the mysqldb module of Python under Windows. Friends who need it can refer to it.

The reason why I wrote this log is because the installation process is a bit sad. This article is currently aimed at the installation of mysqldb on Windows operating systems. To install the mysqldb module of Python, of course, first find some official websites to download: https://pypi.python.org/pypi/MySQL-python. After downloading, cmd into the MySQL-python-1.2.3 folder, execute the python setup.py install command as usual to install this module, and then an error is reported:

This The error is obvious, print

Before running python, you should first determine which versions of python are supported by each version of mysqldb. Some screenshots are as follows:

mysql-python1.2.5 is the latest version. This version supports mysql3.23-5.5, python2.4-2.7, but does not support python3. series. During the installation, the current system's Python is 3.7.11. When uninstalling, an error is reported:

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.

I guess this problem may be caused by file defects, so I tried some solutions mentioned on the Internet:

Method 1: Rerun the installer, select repair, and then uninstall after repairing. (Result: useless, another network exception error was reported during repair)
Method 2: Install a different version of python, and then uninstall python3.7.11. (Result: useless, the files generated by installing the new version will not repair the old ones. Missing version file)
Method 3: Delete the registry information, or use Your Unin-staller! to forcefully delete python3.7.11. (Result: The deletion was finally successful,

ps: http:/ /wenku.baidu.com/link?url=dujEO65nXySNvwUyDJVR5kmbrlcqp7WsvhLFGN_7L5q-58EoVjyw4DjiTS_J5PomPzgvdG69uulXDI8TbMgJlXk9Y-ayHs8qOD3Z3AomBU7, there is product registration in the link)

or this article: http://www .jb51.net/softjc/500307.html

Of the above 3 solutions, only the third and most violent method solved my problem. Some netizens can use the first 2 methods, and the problem can be solved after operation. After uninstalling the higher version of python, I finally installed the lower version of python.

Then I installed mysqldb, and then another error was reported: the c language compilation environment is missing, and I need to download a VC environment. This is actually quite easy to handle. There is a download link in the error message (I forgot to take a screenshot, sorry) https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266. Download VCForPython27.msi This error will not be reported after installation. But another error is reported. (I forgot to take a screenshot again), and then I felt it was necessary to check the readme in the MySQL-python-1.2.3 folder. It usually records how to install and how to use it. The translated screenshots of some important information about Windows system installation are as follows:


Windows.......
我不做Windows。 但是如果有人给我提供了一个包Windows,我会使它可用。 不要问我有关Windows的帮助因为我不能帮助你。
一般来说,运行setup.py与上面类似::
 C:\ ...> python setup.py install C:\ ...> python setup.py bdist_wininst
后面的示例应该构建一个Windows安装程序包,如果你有正确的工具。 无论如何,你必须有一个C编译器。另外,你必须设置一个环境变量(mysqlroot)这是MySQL安装的路径。 在理论上,它会的可能从注册表中获取这些信息,但是像我说的,
我不做Windows,但我会接受这样做的补丁。
在Windows上,您肯定必须编辑site.cfg,因为有在MySQL包中没有mysql_config。

Then I started to install mysql silently, went to the official website and downloaded version 5.5.7, and installed and verified the connection. DB always reports an error: ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)

In this Baidu, add skip- in my.ini in the installation folder Just grant-tables


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

Then you can connect to the DB normally and access the DB. Now I think there should be no problem. However, during installation, another error was reported. :


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[&#39;registry_key&#39;]) 
WindowsError: [Error 2]

Possible solution: Open setup_windows.py, then comment out the two lines of code for registry operations, and add one line of code:


#serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options[&#39;registry_key&#39;]) 
 #mysql_root, dummy = _winreg.QueryValueEx(serverKey,&#39;Location&#39;) 
 mysql_root = "C:\Program Files\MySQL\MySQL Server 5.5" #MySQL目录

Then continued the installation, and another error was reported:

Possible solution: 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 Code of setup_windows.py:


#serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options[&#39;registry_key&#39;]) 
 #mysql_root, dummy = _winreg.QueryValueEx(serverKey,&#39;Location&#39;) 
 mysql_root = "C:\Program Files\MySQL\MySQL Connector C 6.0.2" #MySQL Connector C 6.0.2目录

Then execute the installation, my God, it finally succeeded.


import MySQLdb

if __name__ == "__main__":
 test= MySQLdb.connect("localhost","root","root1234","mysql" )
 cur = test.cursor()
 cur.execute(&#39;show databases;&#39;)
 for data in cur.fetchall():
  print data

The print result is as follows:


D:\Python27\python.exe D:/untitled/mysql_test.py
(&#39;information_schema&#39;,)
(&#39;mysql&#39;,)
(&#39;performance_schema&#39;,)
(&#39;test&#39;,)

Process finished with exit code 0

I have installed third-party libraries when I was learning RF but never like this I'm sad, it's possible that I was using a low version of python at that time, and there were compilation environments for various programs on the machine at that time. However, a problem was exposed, that is, when installing third-party libraries, there was no universal method to help with quick installation. Based on The bloody experience is summarized as follows:
1. Before installation, read the read me in the installation file and some instructions on the download page (generally the author will write the installation manual and test document, no matter what type it is) The operating system will be introduced more or less).

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

3. Determine what other environments and dependent software are needed when installing the third-party library.

The above is the detailed content of How to install python's mysqldb module under windows. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How Do I Drop or Modify an Existing View in MySQL?How Do I Drop or Modify an Existing View in MySQL?May 16, 2025 am 12:11 AM

TodropaviewinMySQL,use"DROPVIEWIFEXISTSview_name;"andtomodifyaview,use"CREATEORREPLACEVIEWview_nameASSELECT...".Whendroppingaview,considerdependenciesanduse"SHOWCREATEVIEWview_name;"tounderstanditsstructure.Whenmodifying

MySQL Views: Which design patterns can I use with it?MySQL Views: Which design patterns can I use with it?May 16, 2025 am 12:10 AM

MySQLViewscaneffectivelyutilizedesignpatternslikeAdapter,Decorator,Factory,andObserver.1)AdapterPatternadaptsdatafromdifferenttablesintoaunifiedview.2)DecoratorPatternenhancesdatawithcalculatedfields.3)FactoryPatterncreatesviewsthatproducedifferentda

What Are the Advantages of Using Views in MySQL?What Are the Advantages of Using Views in MySQL?May 16, 2025 am 12:09 AM

ViewsinMySQLarebeneficialforsimplifyingcomplexqueries,enhancingsecurity,ensuringdataconsistency,andoptimizingperformance.1)Theysimplifycomplexqueriesbyencapsulatingthemintoreusableviews.2)Viewsenhancesecuritybycontrollingdataaccess.3)Theyensuredataco

How Can I Create a Simple View in MySQL?How Can I Create a Simple View in MySQL?May 16, 2025 am 12:08 AM

TocreateasimpleviewinMySQL,usetheCREATEVIEWstatement.1)DefinetheviewwithCREATEVIEWview_nameAS.2)SpecifytheSELECTstatementtoretrievedesireddata.3)Usetheviewlikeatableforqueries.Viewssimplifydataaccessandenhancesecurity,butconsiderperformance,updatabil

MySQL Create User Statement: Examples and Common ErrorsMySQL Create User Statement: Examples and Common ErrorsMay 16, 2025 am 12:04 AM

TocreateusersinMySQL,usetheCREATEUSERstatement.1)Foralocaluser:CREATEUSER'localuser'@'localhost'IDENTIFIEDBY'securepassword';2)Foraremoteuser:CREATEUSER'remoteuser'@'%'IDENTIFIEDBY'strongpassword';3)Forauserwithaspecifichost:CREATEUSER'specificuser'@

What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool