Home > Database > Mysql Tutorial > How to install python's mysqldb module under windows

How to install python's mysqldb module under windows

黄舟
Release: 2017-09-08 11:32:23
Original
2003 people have browsed it

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。
Copy after login

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
Copy after login

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]
Copy after login

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目录
Copy after login

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目录
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template