python mysqldb module installation

python mysqldb module installation

      The reason why I wrote this log is because the installation process is a bit sadistic. Currently this article is for the installation of mysqldb on the windows operating system. To install the mysqldb module of python, of course, first of all, find some official websites to download: https://pypi.python.org/pypi/MySQL-python. After downloading, cmd enters the MySQL-python-1.2.3 folder, and executes the python setup.py install command to install this module as usual, and then an error is reported:

  

   This error is obvious, print

  Before starting python, you should first determine which versions of python are supported by the current versions 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. Since the current system's python is 3.7.11 during installation, 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 It
       is estimated that this problem may be caused by file defects, so I tried some solutions mentioned on the Internet:
Method 1: Re-run the installer, select repair, and then uninstall after repairing. (result: useless, another network exception error is 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 version files. Missing)
Method 3: Delete the registry information, or use Your Unin-staller! to force delete python3.7.11. (result: finally deleted successfully, ps: http://wenku.baidu.com/link?url=dujEO65nXySNvwUyDJVR5kmbrlcqp7WsvhLFGN_7L5q -58EoVjyw4DjiTS_J5PomPzgvdG69uulXDI8TbMgJlXk9Y-ayHs8qOD3Z3AomBU7, there is product registration in the link)
       The above 3 solutions are only the third most violent method to solve my problem. Some netizens can use the first two, and the problem can also be solved after operation. After uninstalling the higher version of python, I finally installed the lower version of python.

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

copy code
Windows.......
I don't do Windows. But if someone provides me with a package Windows, I'll make it available. Don't ask me for help with Windows because I can't help you.
In general, running setup.py is similar to above::
   C:\ ...> python setup.py install    C:\ ...> python setup.py bdist_wininst
The latter example should build a Windows installer package if you have the right tools. You must have a C compiler anyway. Also, you must set an environment variable (mysqlroot) which is the path to the MySQL installation. In theory it would be possible to get this information from the registry, but like I said, 
I don't do Windows, but I'll accept patches that do.

On Windows, you definitely have to edit site.cfg, since there is no mysql_config in the MySQL package.    

copy code


      然后开始默默的安装mysql,去官网下了个5.5.7版本的,安装验证连接DB时一直报错:ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)    

      这个百度下,在安装文件夹的my.ini里增加skip-grant-tables就可以了

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

     然后就能正常连接DB并访问DB了,这下我觉得应该没问题,然而安装时,又报了一个错:

copy code
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]  
copy code

 可行的解决方法:打开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 Server 5.5" #MySQL目录  

   然后接着安装,又报了一个错:

可行的解决方法:下载MySQL Connector(地址:http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-win32.msi/from/http://ftp.jaist.ac.jp/pub/mysql/ ),然后修改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目录<span style="color:#ff0000;">  
/span>  

 接着执行安装,天啊,终于成功了。

copy code
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
copy code

打印结果如下:

copy code
D:\Python27\python.exe D:/untitled/mysql_test.py
('information_schema',)
('mysql',)
('performance_schema',)
('test',)

Process finished with exit code 0
copy code

     I have installed a third-party library when I was learning RF before, but I have never been so cruel. It is also possible that the low version of python was used at that time, and there were various program compilation environments on the machine at that time, but a problem was exposed, that is, the installation There is no general method to help the quick installation of the three-party library. Based on the experience of dog blood, the following summary is made:
1. Before installation, read the read me in the installation file and some instructions on the download page (generally, the author will write Installation manuals and test documents, no matter what type of operating system, will be introduced more or less).

2. Determine which version of python the python tripartite library supports. At present, python2.7.11 is still very good.

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324765854&siteId=291194637