Using python with MySQL

Discussion in 'Python' started by HMS Surprise, May 1, 2007.

  1. HMS Surprise

    HMS Surprise Guest

    Greetings,

    I need to peform some simple queries via MySQL. Searching the list I
    see that folks are accessing it with python. I am very new to python
    and pretty new to MySQL too. Would appreciate it if you could point me
    to some documentation for accessing MySQL via python. Something of the
    "Python and MySQL for Dummies" caliber would be about my speed, but of
    course I will be thankful for anything offered.

    Thanks,

    jvh
     
    HMS Surprise, May 1, 2007
    #1
    1. Advertising

  2. HMS Surprise

    Greg Donald Guest

    On 1 May 2007 12:40:20 -0700, HMS Surprise <> wrote:
    > I need to peform some simple queries via MySQL. Searching the list I
    > see that folks are accessing it with python. I am very new to python
    > and pretty new to MySQL too. Would appreciate it if you could point me
    > to some documentation for accessing MySQL via python. Something of the
    > "Python and MySQL for Dummies" caliber would be about my speed, but of
    > course I will be thankful for anything offered.



    http://mysql-python.sourceforge.net/



    --
    Greg Donald
    http://destiney.com/
     
    Greg Donald, May 1, 2007
    #2
    1. Advertising

  3. HMS Surprise

    Shafik Guest

    On May 1, 10:40 pm, HMS Surprise <> wrote:
    > Greetings,
    >
    > I need to peform some simple queries via MySQL. Searching the list I
    > see that folks are accessing it with python. I am very new to python
    > and pretty new to MySQL too. Would appreciate it if you could point me
    > to some documentation for accessing MySQL via python. Something of the
    > "Python and MySQL for Dummies" caliber would be about my speed, but of
    > course I will be thankful for anything offered.
    >
    > Thanks,
    >
    > jvh


    hi,
    download this module:
    http://sourceforge.net/projects/mysql-python
    and look at the tutorial here:
    http://www.kitebird.com/articles/pydbapi.html
     
    Shafik, May 1, 2007
    #3
  4. HMS Surprise

    HMS Surprise Guest

    On May 1, 2:58 pm, "Greg Donald" <> wrote:
    > On 1 May 2007 12:40:20 -0700, HMS Surprise <> wrote:
    >
    > > I need to peform some simple queries via MySQL. Searching the list I
    > > see that folks are accessing it with python. I am very new to python
    > > and pretty new to MySQL too. Would appreciate it if you could point me
    > > to some documentation for accessing MySQL via python. Something of the
    > > "Python and MySQL for Dummies" caliber would be about my speed, but of
    > > course I will be thankful for anything offered.

    >
    > http://mysql-python.sourceforge.net/
    >
    > --
    > Greg Donaldhttp://destiney.com/



    Most excellent!

    Many thanks, Greg. I'll get started reading pronto.


    jvh
     
    HMS Surprise, May 1, 2007
    #4
  5. HMS Surprise

    HMS Surprise Guest

    HMS Surprise, May 1, 2007
    #5
  6. HMS Surprise

    hlubenow Guest

    HMS Surprise wrote:

    > Greetings,
    >
    > I need to peform some simple queries via MySQL. Searching the list I
    > see that folks are accessing it with python. I am very new to python
    > and pretty new to MySQL too. Would appreciate it if you could point me
    > to some documentation for accessing MySQL via python. Something of the
    > "Python and MySQL for Dummies" caliber would be about my speed, but of
    > course I will be thankful for anything offered.
    >
    > Thanks,
    >
    > jvh


    There's even another approach:
    If you're on Linux, Qt3 may be available. Install its Python-bindings. Given
    a database "MyDatabase", with password "MyPassword" for user "root" and
    inside the database a table "MyTable", you can then do something like this:

    ----------------------------------------------------
    #!/usr/bin/env python

    from qt import *
    import sys
    from qtsql import QSqlDatabase, QSqlQuery

    app = QApplication(sys.argv)

    DB = QSqlDatabase("QMYSQL3", "MyDatabase", app)

    DB.setDatabaseName("MyDatabase")
    DB.setUserName("root")
    DB.setPassword("MyPassword")
    DB.setHostName("localhost")
    DB.open()

    c = DB.execStatement("select * from MyTable")

    while c.next():
    print c.value(0).toString()
    print c.value(1).toString()
    print c.value(2).toString()
    print c.value(3).toString()
    c.first()

    c2 = DB.execStatement("select count(*) from MyTable")
    c2.next()

    print c2.value(0).toString()
    ----------------------------------------------------

    Some further documentation:
    http://www.arl.hpc.mil/ice/Manuals/PyQt/t1.html
    http://doc.trolltech.com/4.2/database.html

    H.
     
    hlubenow, May 3, 2007
    #6
  7. HMS Surprise

    hlubenow Guest

    hlubenow wrote:

    > There's even another approach: ...


    On the other hand you may be better off with the "mysql-python"-module.

    Anyway, here's a nice overview over the most commonly used MySQL-commands
    (The commands should speak for themselves, even if the explanations are in
    German):

    http://www.linux-club.de/ftopic49585.html

    H.
     
    hlubenow, May 3, 2007
    #7
    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. Ravi
    Replies:
    6
    Views:
    1,414
    Suchandra Thapa
    Jul 21, 2003
  2. Replies:
    2
    Views:
    6,203
  3. washakie
    Replies:
    4
    Views:
    930
    washakie
    Jan 15, 2008
  4. dave
    Replies:
    4
    Views:
    1,378
    Steve Holden
    Nov 18, 2010
  5. julian
    Replies:
    8
    Views:
    457
    Avatar
    Apr 6, 2006
Loading...

Share This Page