MySQL with Python

  • Thread starter রà§à¦¦à§à¦° বà§à¦¯à¦¾à¦£à¦¾à¦°à§à¦œà§€
  • Start date
À

রà§à¦¦à§à¦° বà§à¦¯à¦¾à¦£à¦¾à¦°à§à¦œà§€

Dear friends,
I am starting a project of creating a database using mySQL(my first
project with database).
I went to my institute library and find that, all books are managing
"mySQL with perl and php"

I am new to python itself and gradually loving it. I mostly use it as an
alternative of shell-script. Since learning a new language for every new
project is not possible(its self assigned project, generally in free
time), can I do a "mySQL with python?"

if yes, can you kindly suggest a book/reference on this?
 
C

Chris Angelico

Dear friends,
I am starting a project of creating a database using mySQL(my first
project with database).
I went to my institute library and find that, all books are managing
"mySQL with perl and php"

I am new to python itself and gradually loving it. I mostly use it as an
alternative of shell-script. Since learning a new language for every new
project is not possible(its self assigned project, generally in free
time), can I do a "mySQL with python?"

if yes, can you kindly suggest a book/reference on this?

It's definitely possible. As far as I know, though, there's no inbuilt
support, so you'll need an add-on module. What platform are you
running on? On Debian Linux, for instance, you can simply "apt-get
install python-mysqldb".

But you may wish to consider using PostgreSQL instead. It's a
generally better database engine than MySQL, and is equally well
supported:

http://wiki.python.org/moin/PostgreSQL

Actually, to be quite honest, I'm surprised there's no module in the
Python stdlib for either of the above. Possibly because there are
several competing options.

ChrisA
 
D

Demian Brecht

if yes, can you kindly suggest a book/reference on this?

There are a few different ways to connect to MySQL, two of which are:

For reference on connecting and querying MySQL through mysql-python,
take a read through http://mysql-python.sourceforge.net/MySQLdb.html.

Another solution is to use SQLAlchemy (http://www.sqlalchemy.org/). The
ORM abstracts a lot of the tedious SQL queries out for you and allows
you to concentrate more on your application's logic.
 
À

রà§à¦¦à§à¦° বà§à¦¯à¦¾à¦£à¦¾à¦°à§à¦œà§€

But you may wish to consider using PostgreSQL instead.
Thanks, as I am very much new in database thing, I am not very aware of
the options I have.
But in my library, I did not found any thing on PostgreSQL.
Though, I will google its support as well, can you kindly let me know if
this is well documented. I can see there mailing list is quite active.
So that may not be a problem though.
 
C

Chris Angelico

Thanks, as I am very much new in database thing, I am not very aware of
the options I have.
But in my library, I did not found any thing on PostgreSQL.
Though, I will google its support as well, can you kindly let me know if
this is well documented. I can see there mailing list is quite active.
So that may not be a problem though.

Postgres itself: http://www.postgresql.org/

I posted a link to some Python-PGSQL libraries in my previous post.

ChrisA
 
D

Dennis Lee Bieber

Dear friends,
I am starting a project of creating a database using mySQL(my first
project with database).
I went to my institute library and find that, all books are managing
"mySQL with perl and php"

I am new to python itself and gradually loving it. I mostly use it as an
alternative of shell-script. Since learning a new language for every new
project is not possible(its self assigned project, generally in free
time), can I do a "mySQL with python?"

if yes, can you kindly suggest a book/reference on this?

First off, how much "managing" do you expect to perform? For
actually managing the MySQL server you're probably better off
downloading the dedicated application (Used to be "MySQL Admin" and a
separate "MySQL QueryBrowser" -- the current download is a unified
"MySQL Workbench").

For routine database /access/ (that is, someone has created the
database user account that will be used), MySQLdb is the Python adapter
to connect to the server. For using THAT, you basically need to know SQL
(MySQL's flavor in particular), along with understanding the DB-API 2
specification (PEP-249) with the MySQLdb documentation (which explains
any limitations or specifics; see http://mysql-python.sourceforge.net/ )

For books, though some are rather old by now:

MySQL for Python
(Albert Lukaszewski; 2010 Packt Publishing)

The Definitive Guide to MySQL 5 3rd Ed
(Michael Kofler; 2005 Apress)[no Python chapter, but does introduce the
now-discontinued Admin and QueryBrowser applications, and introduces the
features of MySQL v5

Managing & Using MySQL 2nd Ed (Reese/Yarger/King; 2002 O'Reilly)[has 5
pages on MySQL with Python]

And a new edition NOT YET RELEASED -- don't know if this edition
includes anything on Python, the 3rd edition does not; but the volume is
huge and may be close to covering what the old MySQL AB "Administrators
Guide" and "Language Reference" books covered.

MySQL 5th Ed
(Paul DuBois; Dec 2012 Addison-Wesley [Developer's Library])
 
R

Roy Smith

Dennis Lee Bieber said:
For routine database /access/ (that is, someone has created the
database user account that will be used), MySQLdb is the Python adapter
to connect to the server. For using THAT, you basically need to know SQL
(MySQL's flavor in particular), along with understanding the DB-API 2
specification (PEP-249) with the MySQLdb documentation (which explains
any limitations or specifics; see http://mysql-python.sourceforge.net/ )

Another possibility is to use some sort of ORM (Object Relational
Mapper), which provides an abstraction layer on top of the raw SQL
layer. Two examples are SQLAlchemy (http://www.sqlalchemy.org/) and
Django (https://www.djangoproject.com/).

A thread on Stack Overflow (http://stackoverflow.com/questions/53428)
mentions some additional Python ORMs you might want to explore.
 

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,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top