Install Python-mysql in cygwin

Source: Internet
Author: User

1 install mysql-5.0.56.tar.gz

Http://down.51cto.com/data/320800

$ Tar-zxvf mysql-5.0.56.tar.gz

$ Mysql-5.0.56 CD

$./Configure -- without-Server
$./Make

A bunch of exceptions related to Readline

mysql.cc:315: error: redefinition of ‘struct _hist_entry’../include/readline/readline.h:53: error: previous definition of ‘struct _hist_entry’mysql.cc:318: error: invalid type in declaration before ‘;’ tokenmysql.cc:318: error: conflicting declaration ‘typedef int HIST_ENTRY’../include/readline/readline.h:56: error: ‘HIST_ENTRY’ has a previous declaration as ‘typedef struct _hist_entry HIST_ENTRY’mysql.cc: In function ‘void initialize_readline(char*)’:mysql.cc:1622: error: ‘rl_completion_func_t’ was not declared in this scopemysql.cc:1622: error: expected primary-expression before ‘)’ tokenmysql.cc:1623: error: ‘rl_compentry_func_t’ was not declared in this scopemysql.cc:1623: error: expected primary-expression before ‘)’ tokenmysql.cc: In function ‘char** new_mysql_completion(const char*, int, int)’:mysql.cc:1649: error: ‘rl_completion_matches’ was not declared in this scope


$ Make clean # Important
$./Configure -- without-server -- without-Readline
$ Make

No more error words. Enter

$ Mysql
Error 2002 (hy000): Can't connect to local MySQL server through socket '/tmp/MySQL. Sock' (2)

MySQL cannot be found. The installation is successful.

2. Install mysql-Python setuptools

Wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download

$ Tar-zxvf MySQL-python-1.2.3.tar.gz

$ MySQL-python-1.2.3 CD

$ Python setup. py build
Traceback (most recent call last ):
File "setup. py", line 5, in <module>
From setuptools import setup, extension
Importerror: No module named setuptools

The prompt does not contain setuptools. "setuptools is a sub-project of Python Enterprise Application Kit (peak). It is an enhanced tool for a group of Python distutilsde tools (applicable
Python 2.3.5 or later versions, and the 64-bit platform is applicable to Python 2.4 or later versions). This allows programmers to easily create and release Python packages, especially those that are dependent on other packages." -- Baidu encyclopedia

Install setuptools smoothly. Refer to a post in Baidu ~

$ Wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
$ Tar zxvf setuptools-0.6c11.tar.gz
$ Setuptools-0.6c11 CD
$ Python setup. py build
$ Python setup. py install

Install Python-MySQL and modify the site. cfg file.

$ MySQL-python-1.2.3 CD

$ Whereis MySQL

MySQL:/usr/local/bin/mysql.exe/usr/local/lib/MySQL

$ Whereis mysql_config
Mysql_config:/usr/local/bin/mysql_config/opt/MySQL/bin/mysql_config

Modified File

[options]# embedded: link against the embedded server library# threadsafe: use the threadsafe client# static: link against a static library (probably required for embedded)embedded = Falsethreadsafe = Falsestatic = True# The path to mysql_config.# Only use this if mysql_config is not on your PATH, or you have some weird# setup that requires it.mysql_config = /usr/local/bin/mysql_config# The Windows registry key for MySQL.# This has to be set for Windows builds to work.# Only change this if you have a different version.# registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0

(A) Release the mysql_config item. The content is the retrieval result of whereis mysql_config. The/opt/MySQL/bin/mysql_config item is not tested. It is estimated that ~

(B) Disable registry_key.

(C) the top three true and false options refer to those in other posts.

$ Python setup. py build
$ Python setup. py install

No prompt for successful installation is displayed, but no error is displayed, :) Test

$ pythonPython 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)[GCC 4.3.4 20090804 (release) 1] on cygwinType "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb/usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-cygwin-1.7.9-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-cygwin-1.7.9-i686.egg/_mysql.pyc, but /cygdrive/d/MySQL-python-1.2.3 is being added to sys.path

It seems that there is a conflict, ls, or you can't understand

/cygdrive/d/MySQL-python-1.2.3$ lsHISTORY                README                 dist           setup.cfg         setup_posix.pyc           testsMANIFEST.in            _mysql.c               doc            setup.py          setup_windows.pyMySQL_python.egg-info  _mysql_exceptions.py   ez_setup.py    setup_common.py   setuptools-0.6c11.tar.gzMySQLdb                _mysql_exceptions.pyc  metadata.cfg   setup_common.pyc  site.cfgPKG-INFO               build                  pymemcompat.h  setup_posix.py    site.cfg.bak

Under Baidu, after install, The mysqldb module has been put into the site-packages directory of Python; however, the same module exists in the current directory, so it may be imported repeatedly. Change the Directory and try again

$ pythonPython 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)[GCC 4.3.4 20090804 (release) 1] on cygwinType "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>>

Success! No error message is displayed.

Mysql-Server check, mysql_test.py

import MySQLdbtry:connection = MySQLdb.connect(user="***",passwd="***",host="*.*.*.*",db="test")except:print "Could not connect to MySQL server."exit( 0 )cursor = connection.cursor()cursor.execute("SELECT parent_id,sku_id FROM datong where sku_id = 0")print "Rows selected:", cursor.rowcount      for row in cursor.fetchall():    print "sku : ", row[0], row[1]cursor.close()
sku :  2147483647 0sku :  2147483647 0sku :  2147483647 0sku :  2147483647 0sku :  2147483647 0

Reference: http://suddymail.org/show-171-1.html

Http://awwsheezy.com/2011/05/03/dbdmysql-dbi-perl-mysql-and-cygwin-together-at-last/

Http://hi.baidu.com/seaweaver/item/1db27a152cefb125f7625cf6




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.