trouble installing MySQLdb (cygwin) + Bonus question

Discussion in 'Python' started by Matthew Roth, Jan 24, 2011.

  1. Matthew Roth

    Matthew Roth Guest

    Hi,
    I'm a python newbie. By newbie I mean two days ago.
    It was suggested to me that I work with python.
    Unfortunately at work I must run this on a windows machiene.

    However, I am having difficultly installing MySQLdb.

    First is it even possible under my current environment?
    I am using python(2.6.5) through cygwin, and have mySQL(Ver 14.14
    Distrib 5.5.8 for Win32) installed in windows 7

    which mysql returns:
    /cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql

    when I run
    python setup.py build it returns:
    --
    $ python setup.py build
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
    File "setup.py", line 15, in <module>
    metadata, options = get_config()
    File "/home/Matt/MySQL-python-1.2.3/setup_posix.py", line 43, in
    get_config
    libs = mysql_config("libs_r")
    File "/home/Matt/MySQL-python-1.2.3/setup_posix.py", line 24, in
    mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    --

    I've explored various avenues all day to no avail. Can anyone offer a
    solution or a direction to work towards. One avenue was ignorning the
    check for posix, and having it run setup_windows, but this just brings
    in problems with _winreg(?) seeing how I have a posix version of
    python through cygwin.

    Lastly, for the bonus question.
    Why MySQLdb why not something like this:
    --
    import os
    cmd = 'mysql -uroot -pxxx db -e "SELECT * FROM tblxxx;"'
    os.system(cmd)

    --

    why is this a poor idea?

    Best,
    Matt
     
    Matthew Roth, Jan 24, 2011
    #1
    1. Advertising

  2. On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
    <> declaimed the following in
    gmane.comp.python.general:

    >
    > I've explored various avenues all day to no avail. Can anyone offer a
    > solution or a direction to work towards. One avenue was ignorning the
    > check for posix, and having it run setup_windows, but this just brings
    > in problems with _winreg(?) seeing how I have a posix version of
    > python through cygwin.
    >

    Maybe you need the development headers for MySQL?

    > Lastly, for the bonus question.
    > Why MySQLdb why not something like this:
    > --
    > import os
    > cmd = 'mysql -uroot -pxxx db -e "SELECT * FROM tblxxx;"'
    > os.system(cmd)


    Passing username/password to a shell command that might be parsed by
    some outside process? Security leak!

    Second -- MySQL is a server model DBMS; it doesn't have to be on the
    local machine.

    Third -- ever heard of TRANSACTIONS? How would you handle a
    transaction if every SQL statement was a totally independent process?
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jan 25, 2011
    #2
    1. Advertising

  3. Matthew Roth

    Matthew Roth Guest

    On Jan 25, 4:30 am, Dennis Lee Bieber <> wrote:
    > On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
    > <> declaimed the following in
    > gmane.comp.python.general:
    >
    >
    >
    > > I've explored various avenues all day to no avail. Can anyone offer a
    > > solution or a direction to work towards. One avenue was ignorning the
    > > check for posix, and having it run setup_windows, but this just brings
    > > in problems with _winreg(?) seeing how I have a posix version of
    > > python through cygwin.

    >
    >         Maybe you need the development headers for MySQL?

    --
    I do believe I have them. Perhaps I need to find the correct way to
    point to them.
    I believe it is looking for the dev headers for a linux client when I
    am using a client for windows via cygwin.

    Or perhaps I should look into installing a separate linux mysql client
    in cygwin.
    I read of a similiar problem with perl, but the documentation felt a
    bit dated and several steps would no longer function correctly.

    >
    > > Lastly, for the bonus question.
    > > Why MySQLdb why not something like this:
    > > --
    > > import os
    > > cmd = 'mysql -uroot -pxxx db -e "SELECT * FROM tblxxx;"'
    > > os.system(cmd)

    >
    >         Passing username/password to a shell command that might be parsed by
    > some outside process? Security leak!

    --
    I do indeed see that. However, all my python calls will be done within
    my local intranet.
    But is this a reason to not use os module at all? fetching a
    dirlisting or mkdir is still
    a valid reason to use the os Module, correct?
    >
    >         Second -- MySQL is a server model DBMS; it doesn't have to be on the
    > local machine.

    --
    unfortunately, for my use it does. We do have an old centOs box here,
    but the mysql running on that is severely outdated and so too is the
    python.
    I have been discouraged from upgrading the former, and the latter I
    was told only if I could do it through yum. Making an altinstall form
    source seems to be
    discouraged. Good news is I think they have decided to upgrade our
    development box.
    >
    >         Third -- ever heard of TRANSACTIONS? How would you handle a
    > transaction if every SQL statement was a totally independent process?
    > --

    No. quite to my embarrassment I haven't. But this is not to say I have
    not used them. It sounds as if I have.
    But, you can put more than one sql statement into a cmdline.
    mysql = "mysql -uuser -ppass db -e \"SELECT CURTIME();
    CREATE TABLE tempTBL (
    freq INT,
    x INT,
    y VARCHAR(255),
    PRIMARY KEY(x, y);

    LOAD XML INFLE 'doc'
    INTO TABLE tempTBL
    ROWS IDENTIFIED BY '<line>';

    INSERT INTO freqTbl(x,y,freq)
    SELECT x,y,freq FROM tempTBL
    ON DUPLICATE KEY UPDATE freq=tempTbl.freq+freqTbl.freq;

    SELECT CURTIME();\"
    os.system(mysql)

    I haven't tested that, but I know it works at the command line.
    I do fully intend to use MySQLdb through python and conduct more of
    the processing and parsing in python. It will be a learning
    experience. I have a background in anthropology, not computer science.
    But I love learning all this, and love that my place of employment
    encourages me to learn this. Unfortunately with self-learning you can
    sometimes miss out on important concepts and still accomplish tasks.

    Thank you for your reply.


    >         Wulfraed                 Dennis Lee Bieber         AF6VN
    >            HTTP://wlfraed.home.netcom.com/
     
    Matthew Roth, Jan 25, 2011
    #3
  4. On Tue, 25 Jan 2011 07:05:50 -0800 (PST), Matthew Roth
    <> declaimed the following in
    gmane.comp.python.general:


    > I do believe I have them. Perhaps I need to find the correct way to
    > point to them.
    > I believe it is looking for the dev headers for a linux client when I
    > am using a client for windows via cygwin.
    >
    > Or perhaps I should look into installing a separate linux mysql client
    > in cygwin.


    Since I don't run cygwin, I couldn't say.

    > I do indeed see that. However, all my python calls will be done within
    > my local intranet.
    > But is this a reason to not use os module at all? fetching a
    > dirlisting or mkdir is still
    > a valid reason to use the os Module, correct?


    The os module, yes... os.system(), no.

    os.mkdir() doesn't spawn an external process, it uses the low-level
    direct runtime call to create a directory. Same with os.listdir().

    os.system() is just a quick way to run an external program with
    minimal interaction. It's also archaic compared to the features of the
    subprocess module.



    > unfortunately, for my use it does. We do have an old centOs box here,
    > but the mysql running on that is severely outdated and so too is the
    > python.
    > I have been discouraged from upgrading the former, and the latter I
    > was told only if I could do it through yum. Making an altinstall form
    > source seems to be
    > discouraged. Good news is I think they have decided to upgrade our
    > development box.


    I meant to imply that using os.system() calls would complicate
    things if the server should ever become its own dedicated machine.

    > >
    > >         Third -- ever heard of TRANSACTIONS? How would you handle a
    > > transaction if every SQL statement was a totally independent process?
    > > --

    > No. quite to my embarrassment I haven't. But this is not to say I have
    > not used them. It sounds as if I have.
    > But, you can put more than one sql statement into a cmdline.
    > mysql = "mysql -uuser -ppass db -e \"SELECT CURTIME();
    > CREATE TABLE tempTBL (
    > freq INT,
    > x INT,
    > y VARCHAR(255),
    > PRIMARY KEY(x, y);
    >
    > LOAD XML INFLE 'doc'
    > INTO TABLE tempTBL
    > ROWS IDENTIFIED BY '<line>';
    >
    > INSERT INTO freqTbl(x,y,freq)
    > SELECT x,y,freq FROM tempTBL
    > ON DUPLICATE KEY UPDATE freq=tempTbl.freq+freqTbl.freq;
    >
    > SELECT CURTIME();\"
    > os.system(mysql)
    >

    No... That does not qualify as a proper transaction. A true
    transaction allows you to rollback the entire sequence should an error
    be detected.. The sequence you list runs in MySQL's default autocommit
    mode (Python db-api compliant adapters are required to turn off
    autocommit; a transaction will be implicitly started, and one must end
    the transaction with a con.commit() or con.rollback() ).

    Using os.system() also means YOU are forced to ensure that data is
    properly escaped and warded against SQL injection attacks. Using the
    MySQLdb parameterized queries means the adapter will "safe" data values
    being supplied to the query.
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jan 25, 2011
    #4
  5. Matthew Roth

    Matthew Roth Guest

    Thank you. I appreciate you explanation and tolerance of my
    ignorance.

    However unfortunate, this still does not solve my major issue.
     
    Matthew Roth, Jan 25, 2011
    #5
  6. Matthew Roth

    John Nagle Guest

    On 1/25/2011 7:05 AM, Matthew Roth wrote:
    > On Jan 25, 4:30 am, Dennis Lee Bieber<> wrote:
    >> On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
    >> <> declaimed the following in
    >> gmane.comp.python.general:


    >> Second -- MySQL is a server model DBMS; it doesn't have to be on the
    >> local machine.

    > --
    > unfortunately, for my use it does. We do have an old centOs box here,
    > but the mysql running on that is severely outdated and so too is the
    > python.


    You can install a MySQL server under Windows, and talk to the server
    from the Cygwin environment. That's a useful way to test.

    John Nagle
     
    John Nagle, Jan 25, 2011
    #6
  7. Matthew Roth

    Matthew Roth Guest

    On Jan 25, 9:34 pm, John Nagle <> wrote:
    > On 1/25/2011 7:05 AM, Matthew Roth wrote:
    >
    > > On Jan 25, 4:30 am, Dennis Lee Bieber<>  wrote:
    > >> On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
    > >> <>  declaimed the following in
    > >> gmane.comp.python.general:
    > >>          Second -- MySQL is a server model DBMS; it doesn't have to be on the
    > >> local machine.

    > > --
    > > unfortunately, for my use it does. We do have an old centOs box here,
    > > but the mysql running on that is severely outdated and so too is the
    > > python.

    >
    >     You can install a MySQL server under Windows, and talk to the server
    > from the Cygwin environment.  That's a useful way to test.
    >
    >                                         John Nagle


    Right, that is precisely what I have. I am able to talk to it from
    cygwin, however, during the installing of the MySQLdb module it cannot
    find the mysql_config. This is because It is not installed? The setup
    sees that I am on a posix system not windows, as python is installed
    in cygwin, a virtual posix system. I am trying to bulid a mysql client
    from source for cygwin, however, I am running into an error there.

    Unless, can I talk to the windows mysql_config? if so, what does that
    look like
     
    Matthew Roth, Jan 25, 2011
    #7
  8. On Tue, Jan 25, 2011 at 5:59 PM, Matthew Roth <> wrote:
    > On Jan 25, 9:34 pm, John Nagle <> wrote:

    ....
    >>     You can install a MySQL server under Windows, and talk to the server
    >> from the Cygwin environment.  That's a useful way to test.
    >>
    >>                                         John Nagle

    >
    > Right, that is precisely what I have. I am able to talk to it from
    > cygwin, however, during the installing of the MySQLdb module it cannot
    > find the mysql_config. This is because It is not installed? The setup
    > sees that I am on a posix system not windows, as python is installed
    > in cygwin, a virtual posix system. I am trying to bulid a mysql client
    > from source for cygwin, however, I am running into an error there.
    >
    > Unless, can I talk to the windows mysql_config? if so, what does that
    > look like

    The obvious answer is to use a Windows python. You haven't explained
    why you think you need to run a cygwin python. Can you explain that?
     
    David Robinow, Jan 25, 2011
    #8
  9. Matthew Roth

    Matthew Roth Guest

    On Jan 25, 6:20 pm, David Robinow <> wrote:
    > On Tue, Jan 25, 2011 at 5:59 PM, Matthew Roth <> wrote:
    > > On Jan 25, 9:34 pm, John Nagle <> wrote:

    > ...
    > >>     You can install a MySQL server under Windows, and talk to the server
    > >> from the Cygwin environment.  That's a useful way to test.

    >
    > >>                                         John Nagle

    >
    > > Right, that is precisely what I have. I am able to talk to it from
    > > cygwin, however, during the installing of the MySQLdb module it cannot
    > > find the mysql_config. This is because It is not installed? The setup
    > > sees that I am on a posix system not windows, as python is installed
    > > in cygwin, a virtual posix system. I am trying to bulid a mysql client
    > > from source for cygwin, however, I am running into an error there.

    >
    > > Unless, can I talk to the windows mysql_config? if so, what does that
    > > look like

    >
    >  The obvious answer is to use a Windows python. You haven't explained
    > why you think you need to run a cygwin python. Can you explain that?



    Good question. There isn't a solid explanation. heretofore, I have
    been using a lot of bash scripting in combination with awk sed and
    some perl. I was directed to look into python. My tasks were becoming
    increasingly complex and memory intensive. I started with a desire to
    connect to a mysql server. For that I needed to install the MySQLdb
    module. I am having difficultly in acomplishment of this task. I
    suppose for the time it has taken, using windows python would have
    been the simpler route.


    Anyway, I have done some tinkering and have moved passed the
    mysql_config problem. Thanks to Davids reminder that I have mysql on
    windows. Meaning when setup.py called setup_posix.py It was
    essentially calling mysql_config. Well mysql_config was in a far off
    folder. I setup a symbolic link and that worked. However I was then
    presented with a new problem. In direct relation to that far off
    folder. Dreaded spaces. (i headed the log)

    --
    running build
    running build_py
    copying MySQLdb/release.py -> build/lib.cygwin-1.7.7-i686-2.6/MySQLdb
    running build_ext
    building '_mysql' extension
    creating build/temp.cygwin-1.7.7-i686-2.6
    gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-
    prototypes -Dversion_info=(1,2,3,'final'
    ,0) -D__version__=1.2.3 -I/usr/include/python2.6 -c _mysql.c -o build/
    temp.cygwin-1.7.7-i686-2.6/_mysql.
    o "-I/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/include" "/MT"
    "/Zi" "/O2" "/Ob1" "/D" "NDEBUG" "-
    DDBUG_OFF"
    gcc: "-I/cygdrive/c/Program: No such file or directory
    --

    there is much more, but obviously the problem is " gcc: "-I/cygdrive/c/
    Program: No such file or directory"

    what I need to do is have it point to /cygdrive/c/Program\ Files/MySQL/
    MySQL\ Server\ 5.5/include and not cygdrive/c/Program Files/MySQL/
    MySQL Server 5.5/include.

    I am currently trying to track that down. I think I am going to leave
    work and go grab some dinner. perhaps I will solve this later tonight.

    Best,
    Matt
     
    Matthew Roth, Jan 25, 2011
    #9
  10. Matthew Roth

    John Nagle Guest

    On 1/25/2011 3:51 PM, Matthew Roth wrote:
    > On Jan 25, 6:20 pm, David Robinow<> wrote:
    >> On Tue, Jan 25, 2011 at 5:59 PM, Matthew Roth<> wrote:
    >>> On Jan 25, 9:34 pm, John Nagle<> wrote:

    >> ...
    >>>> You can install a MySQL server under Windows, and talk to the server
    >>>> from the Cygwin environment. That's a useful way to test.

    >>
    >>>> John Nagle

    >>
    >>> Right, that is precisely what I have. I am able to talk to it from
    >>> cygwin, however, during the installing of the MySQLdb module it cannot
    >>> find the mysql_config. This is because It is not installed? The setup
    >>> sees that I am on a posix system not windows, as python is installed
    >>> in cygwin, a virtual posix system. I am trying to bulid a mysql client
    >>> from source for cygwin, however, I am running into an error there.

    >>
    >>> Unless, can I talk to the windows mysql_config? if so, what does that
    >>> look like

    >>
    >> The obvious answer is to use a Windows python. You haven't explained
    >> why you think you need to run a cygwin python. Can you explain that?

    >
    >
    > Good question. There isn't a solid explanation. heretofore, I have
    > been using a lot of bash scripting in combination with awk sed and
    > some perl. I was directed to look into python. My tasks were becoming
    > increasingly complex and memory intensive. I started with a desire to
    > connect to a mysql server. For that I needed to install the MySQLdb
    > module. I am having difficultly in acomplishment of this task. I
    > suppose for the time it has taken, using windows python would have
    > been the simpler route.


    Oh. And all this time, I thought it was because you needed to
    run on a Linux server and were using Cygwin for debugging.

    I routinely develop Python on Windows and run on Linux servers.
    This works fine, provided that you can find versions of any necessary C
    modules for Python for both platforms.

    John Nagle
     
    John Nagle, Jan 26, 2011
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Perflubron

    Installing MySQLdb under Cygwin

    Perflubron, Oct 10, 2003, in forum: Python
    Replies:
    4
    Views:
    627
    Perflubron
    Oct 14, 2003
  2. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    Basic import Questions (with bonus profiling question)

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Aug 31, 2006, in forum: Python
    Replies:
    0
    Views:
    259
    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
    Aug 31, 2006
  3. Lojastar.com
    Replies:
    0
    Views:
    535
    Lojastar.com
    Mar 1, 2008
  4. Lojastar.com
    Replies:
    0
    Views:
    1,867
    Lojastar.com
    Mar 1, 2008
  5. david.karr
    Replies:
    2
    Views:
    202
    david.karr
    Jul 1, 2010
Loading...

Share This Page