trouble installing MySQLdb (cygwin) + Bonus question

M

Matthew Roth

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
 
D

Dennis Lee Bieber

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:

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?
 
M

Matthew Roth

        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.
        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.
 
D

Dennis Lee Bieber

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.
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.
 
M

Matthew Roth

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

However unfortunate, this still does not solve my major issue.
 
J

John Nagle

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
 
M

Matthew Roth

    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
 
D

David Robinow

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?
 
M

Matthew Roth

 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
 
J

John Nagle

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top