Using python with MySQL

H

HMS Surprise

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
 
G

Greg Donald

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/
 
S

Shafik

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
 
H

hlubenow

HMS said:
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.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top