473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Native ODBC access for python on linux?

I'm getting my feet wet with making Python talk to MySQL via ODBC. I
started on Windows, and it went smoothly enough due to the ODBC stuff
that apparently is native to Python at least on windows (I've been
following ch. 13 of Mark Hammond's py on win32 book).

But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
python 2.3.5 and mysql. I'd like to stick with packages that are
native to python, rather than relying on external stuff (e.g., MySQLdb
and mxODBC). Is this possible, or do I have to use 3rd party pieces to
use ODBC with Python under linux?
As an aside, I've only used ODBC to access db's, period. I've never
used, for example, MySQL's API for working with a MySQL db. I'm
curious to see what that looks like, if anyone has any examples
(python, c, or otherwise).

Thanks in advance for any help.
-Bill

Jul 21 '05 #1
10 3243
ODBC is a vanilla interface that puts a layer between the program
and the database. In theory, this would allow you to write a
program that supports ODBC compliant databases and it would work
with any of them. In practice it always seems like this doesn't
work as well as everyone had hoped (performance is quite often a
problem with ODBC interface and time/date handling can be an
issue).

There are people that provide ODBC drivers for Linux but normally
they are used to communcate back to MSSQL servers or other Windows
applications from Linux box.

The native interfaces are almost always better performing and
support more features because ODBC is basically a lowest common
denominator approach. The native API can provide access to all
the (even unique) features of the particular database

IMHO-For Python to MySQL on Linux use the native interface is
the way to go.

Larry Bates

ca********@gmail.com wrote:
I'm getting my feet wet with making Python talk to MySQL via ODBC. I
started on Windows, and it went smoothly enough due to the ODBC stuff
that apparently is native to Python at least on windows (I've been
following ch. 13 of Mark Hammond's py on win32 book).

But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
python 2.3.5 and mysql. I'd like to stick with packages that are
native to python, rather than relying on external stuff (e.g., MySQLdb
and mxODBC). Is this possible, or do I have to use 3rd party pieces to
use ODBC with Python under linux?
As an aside, I've only used ODBC to access db's, period. I've never
used, for example, MySQL's API for working with a MySQL db. I'm
curious to see what that looks like, if anyone has any examples
(python, c, or otherwise).

Thanks in advance for any help.
-Bill

Jul 21 '05 #2
I concur with Larry. I find that by properly abstracting the database
connection code in my own class, I can then use any DB-API-compliant
Python module to connect to a variety of databases. I use for example
cxOracle to connect to Oracle and kinterbasdb to connect to firebird. I
haven't tried connecting to MySQL natively yet, but I don't think it
would be any different.

Grig

Jul 21 '05 #3

<ca********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm getting my feet wet with making Python talk to MySQL via ODBC. I
started on Windows, and it went smoothly enough due to the ODBC stuff
that apparently is native to Python at least on windows (I've been
following ch. 13 of Mark Hammond's py on win32 book).

But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
python 2.3.5 and mysql. I'd like to stick with packages that are
native to python, rather than relying on external stuff (e.g., MySQLdb
and mxODBC). Is this possible, or do I have to use 3rd party pieces to
use ODBC with Python under linux?
As an aside, I've only used ODBC to access db's, period. I've never
used, for example, MySQL's API for working with a MySQL db. I'm
curious to see what that looks like, if anyone has any examples
(python, c, or otherwise).

Thanks in advance for any help.
-Bill


We have a Linux/Apache/MySQL server. We use the ODBC driver to write
Windows clients using VB. I only understand ODBC as a means to bring the
Linux/Apache/MySQL to speaking terms with the Microsoft world. ODBC serves
as the translator between these 2 alien systems.

Although I hear rumors about ODBC drivers on Linux, I confess I don't
understand the need. Certainly you can use Python with the MySQLdb module
from any Linux machine and query away at the server. As long as the MySQL
server accepts your IP/usr/pwd, it will respond to the SQL you pass it from
Python.

IOW - who/what needs an ODBC driver here?
Thomas Bartkus
Jul 21 '05 #4
Can you tell me what I have to use in order to utilize the MySQL native
API? There's some gap (chasm, really) in my knowledge that is keeping
me from following that route. If you could provide a small example or
a couple names, that would be extremely helpful.

Thanks again for your time.

Larry Bates wrote:
ODBC is a vanilla interface that puts a layer between the program
and the database. In theory, this would allow you to write a
program that supports ODBC compliant databases and it would work
with any of them. In practice it always seems like this doesn't
work as well as everyone had hoped (performance is quite often a
problem with ODBC interface and time/date handling can be an
issue).

There are people that provide ODBC drivers for Linux but normally
they are used to communcate back to MSSQL servers or other Windows
applications from Linux box.

The native interfaces are almost always better performing and
support more features because ODBC is basically a lowest common
denominator approach. The native API can provide access to all
the (even unique) features of the particular database

IMHO-For Python to MySQL on Linux use the native interface is
the way to go.

Larry Bates

ca********@gmail.com wrote:
I'm getting my feet wet with making Python talk to MySQL via ODBC. I
started on Windows, and it went smoothly enough due to the ODBC stuff
that apparently is native to Python at least on windows (I've been
following ch. 13 of Mark Hammond's py on win32 book).

But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
python 2.3.5 and mysql. I'd like to stick with packages that are
native to python, rather than relying on external stuff (e.g., MySQLdb
and mxODBC). Is this possible, or do I have to use 3rd party pieces to
use ODBC with Python under linux?
As an aside, I've only used ODBC to access db's, period. I've never
used, for example, MySQL's API for working with a MySQL db. I'm
curious to see what that looks like, if anyone has any examples
(python, c, or otherwise).

Thanks in advance for any help.
-Bill


Jul 21 '05 #5
1. Download and install MySQL-python from
<http://sourceforge.net/project/showfiles.php?group_id=22307&package_id=15775>

2. Try to connect to a MySQL database that you have running. In this
example I'm connecting to the bugs database installed with Bugzilla,
and I'm connecting as MySQL user root (not recommended for 'production'
code):

# python
Python 2.4 (#1, Nov 30 2004, 16:42:53)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import MySQLdb
from pprint import pprint
conn = MySQLdb.connect(db='bugs', user='root', passwd='***')
cursor = conn.cursor()
cursor.execute('select * from groups') 7L data = cursor.fetchall()
print data ((1L, 'tweakparams', 'Can tweak operating parameters', 0, '', 1), (2L,
'editusers', 'Can edit or disable users', 0, '', 1), (4L,
'creategroups', 'Can create and destroy groups.', 0, '', 1), (8L,
'editcomponents', 'Can create, destroy, and edit components.', 0, '',
1), (16L, 'editkeywords', 'Can create, destroy, and edit keywords.', 0,
'', 1), (32L, 'editbugs', 'Can edit all aspects of any bug.', 0, '.*',
1), (64L, 'canconfirm', 'Can confirm a bug.', 0, '.*', 1)) pprint(data) ((1L, 'tweakparams', 'Can tweak operating parameters', 0, '', 1),
(2L, 'editusers', 'Can edit or disable users', 0, '', 1),
(4L, 'creategroups', 'Can create and destroy groups.', 0, '', 1),
(8L, 'editcomponents', 'Can create, destroy, and edit components.', 0,
'', 1),
(16L, 'editkeywords', 'Can create, destroy, and edit keywords.', 0,
'', 1),
(32L, 'editbugs', 'Can edit all aspects of any bug.', 0, '.*', 1),
(64L, 'canconfirm', 'Can confirm a bug.', 0, '.*', 1))


For more info on how to use the MySQLdb module, see the docs at
<http://sourceforge.net/docman/?group_id=22307>

Hope this helps,

Grig

Jul 21 '05 #6
"Thomas Bartkus" <th***********@comcast.net> writes:
Although I hear rumors about ODBC drivers on Linux, I confess I don't
understand the need. Certainly you can use Python with the MySQLdb module
from any Linux machine and query away at the server. As long as the MySQL
server accepts your IP/usr/pwd, it will respond to the SQL you pass it from
Python.

IOW - who/what needs an ODBC driver here?


ODBC provides one thing that db native api's don't - binary
interoperability. If you have a binary application that talks odbc,
you can talk to pretty much any db that someone has writte an odbc
driver for. To talk to the db native api, the application has to be
built against that api.

For instance, I use the unixODBC driver to connect applix office's
spreadsheet tool to my postgresql databases.

If everything you run is open source - especially if it's written in
Python - this is pretty much irrelevant.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 21 '05 #7
All,

This info was very helpful, and I'm up and running with MySQLdb on
linux, and the native ODBC support on Windows.

One last question I have: In vbs (specifically with .asp) I can make a
connection to an ODBC provide _without_ the need to specify a system
DSN in the Control Panel. It's easy to do with MySQLdb.connect(
host,user,pass,etc), but is this possible with the ODBC module in
Python on win32?

Thanks again for all the help. This has really narrowed the gap in my
knowledge significantly.

Jul 21 '05 #8
<ca********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
All,

This info was very helpful, and I'm up and running with MySQLdb on
linux, and the native ODBC support on Windows.

One last question I have: In vbs (specifically with .asp) I can make a
connection to an ODBC provide _without_ the need to specify a system
DSN in the Control Panel. It's easy to do with MySQLdb.connect(
host,user,pass,etc), but is this possible with the ODBC module in
Python on win32?


Ahhh - But that's the point!

If you are "up and running with MySQLdb on linux" then you should be up and
running with with the same code on Windows. The exact same Python script
you run on Linux will work for you on windows! I *think* you might be able
to attach the ODBC driver but it would be a complication and an unnecessary
one at that. Just point MySQLdb.connect() at the servers IP address.

Go to SourceForge and download the MySQLdb installation for win32
[MySQL-python.exe-1.2.0.win32-py2.4.exe].

Sometimes you can't believe it because it's too easy :-)
Thomas Bartkus
Jul 21 '05 #9
I know... I'm expecting pain, and when that pain doesn't arrive I
assume that I did something wrong.

Actually, I was using the odbc/dbi stuff that ships with the win32
distribution for my windows work, and using MySQLdb for my linux work.
Most of the code is the same. But I suppose the big benefit of using
MySQLdb on both (which certainly works) is that there is no abiguity as
to what the user is running for an OS. You don't have a special case
"If you're on Windows, do this; if you're on linux, do that"...
Rather, by having everyone indiscriminately require MySQLdb, then that
forces a unity. That's probably the way to go, huh?

Jul 21 '05 #10
That's exactly the way to go. In my case, I'm using cx_Oracle to
connect from Python to Oracle and the same exact code runs on Windows,
Linux, Solaris and soon on AIX.

Grig

Jul 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marek Kotowski | last post by:
Hi, I am new to MySQL and PHP programming. What is the practical difference between MySQL ODBC functions (3.51 Driver) and native mysql support in PHP (I mean "mysql_" functions available in...
0
by: Nagendra | last post by:
Hi all, I need to access an Oracle database through a python script using ODBC drivers(currently i have eval copies of Easysoft and datadirect Oracle ODBC drivers). Desired platforms are solaris,...
4
by: flupke | last post by:
Hi, at work we use a solid database and i need to develop an application that accesses it. Problem is the drivers: i only have some dll's lying around and jar. On winsdows i could get by by...
3
by: Joe | last post by:
Python 2.4 Windows XP SP2 MS Access 2000 mx.ODBC 2.0.7 Problem data truncation occuring (here's the actual error message): mxODBC.Warning: ('01004', 5, ' String data, right truncated on...
13
by: Graham | last post by:
I need a SQL Server or ODBC package for Python. Can anyone help please? Have search the Python packages under Database and there is no reference to either SQL Server or ODBC. Thanks Graham
2
by: Simon Faulkner | last post by:
Hi All, I am new to Cygwin and am hoping that someone here will be able to tell me how to get ODBC running in Python on Cygwin. Maximum gratefullness... Simon
4
by: hot.favorite | last post by:
Hi, I'm fairly new to Python so please pardon any dumbness on my part. I plan to write an app in Python that will run on Linux and would need to connect to Oracle and MySQL. I could use...
2
by: Philippe Martin | last post by:
Hi, I understand that access can be accessed through an ODBC driver under windows (instead of Jet). I am wondering if the same can be done under Linux. Regards, Philippe
3
by: harsha.patibandla | last post by:
We have a webserver, Apache, hosted on Linux and we use php as the scripting language. Now, I am developing a form which will fill up a Microsoft Access database (on a Windows machine). For this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.