How 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['registry_key']) 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['registry_key']) #mysql_root, dummy = _winreg.QueryValueEx(serverKey,'Location') 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['registry_key']) #mysql_root, dummy = _winreg.QueryValueEx(serverKey,'Location') 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('show databases;') for data in cur.fetchall(): print data
The print result 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 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.
