Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

MySQLdb

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


hmartires at cultalg

Feb 21, 2002, 7:40 AM

Post #1 of 16 (1157 views)
Permalink
MySQLdb

Where i can find an "how to" to learn working with MySQLdb module.
I have downloaded from sourceforge and install it, but there is no much
information on how to use it.
Any one knows where i can get it ?

Tanks in advance


gimbo at ftech

Feb 21, 2002, 7:50 AM

Post #2 of 16 (1103 views)
Permalink
MySQLdb [In reply to]

> Where i can find an "how to" to learn working with MySQLdb module.
> I have downloaded from sourceforge and install it, but there is no
> much information on how to use it. Any one knows where i can get
> it?

(Think I just sent this to the wrong address by mistake, but apologies
if it comes through twice...)

http://python.org/topics/database/DatabaseAPI-2.0.html

http://sourceforge.net/docman/?group_id=22307

--
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.


hmartires at cultalg

Feb 21, 2002, 9:42 AM

Post #3 of 16 (1112 views)
Permalink
MySQLdb [In reply to]

That ones i have already read, but they don't explain a lot.
Don't you know more documentation ?

"Andy Gimblett" <gimbo [at] ftech> wrote in message
news:mailman.1014303155.8362.python-list [at] python
> > Where i can find an "how to" to learn working with MySQLdb module.
> > I have downloaded from sourceforge and install it, but there is no
> > much information on how to use it. Any one knows where i can get
> > it?
>
> (Think I just sent this to the wrong address by mistake, but apologies
> if it comes through twice...)
>
> http://python.org/topics/database/DatabaseAPI-2.0.html
>
> http://sourceforge.net/docman/?group_id=22307
>
> --
> Andy Gimblett - Programmer - Frontier Internet Services Limited
> Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
> Statements made are at all times subject to Frontier's Terms and
> Conditions of Business, which are available upon request.
>
>


smk at goeci

Feb 22, 2002, 11:15 AM

Post #4 of 16 (1136 views)
Permalink
MySQLdb [In reply to]

For starters, you could try
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65235

"Hugo Martires" <hmartires [at] cultalg> wrote in message
news:XD7d8.203$zZ4.2649220 [at] newsserver
> Where i can find an "how to" to learn working with MySQLdb module.
> I have downloaded from sourceforge and install it, but there is no much
> information on how to use it.
> Any one knows where i can get it ?
>
> Tanks in advance
>
>


FBatista at uniFON

Jan 25, 2005, 1:12 PM

Post #5 of 16 (1103 views)
Permalink
RE: MySQLdb [In reply to]

[Daniel Bowett]

#- The problem I have is that it takes just over two minuted to
#- execute the
#- 3000 insert statements which seems really slow! I am running it on a
#- machine with a 1.5 Ghz Pentium M Processor and Gig Of Ram. I
#- dont think
#- the machine is to blame for the speed because during execution the
#- processor sits at about 10% and there is loads of free RAM.
#-
#- Does anyone know if this sort of speed sounds right?

Well, I made the following code.

mod_mysql is mine, but is just a wrapper around the standard module. Here I
only use the .accion() method of the Consulta object, that let me send an
action (query, insert, etc) to the database.

So I generate a temporary table of four fields, and prepared a list of 3000
entries, each one is a tuple of four elements: ten characters choosed
randomly.

---

import random, string, time
import mod_mysql

bdd = mod_mysql.Consulta("pytonisa", "fbatista", "password", "otainfo")

bdd.accion("create temporary table tmp.prueba (c1 char(10), c2 char(10), c3
char(10), c4 char(10));")

r = random.Random()
let = string.letters + string.digits
fuente = [tuple([''.join(r.sample(let, 10)) for j in range(4)]) for x in
range(3000)]

t = time.time()
for reg in fuente:
bdd.accion('insert into tmp.prueba values ("%s", "%s", "%s", "%s");' %
tuple(reg))
print time.time() - t

---

I only measure the time of the inserts. It took 0.269818067551 seconds.

I'm using a Pentium 4 2.8 GHz, 256 MB of RAM, with Fedora Core 2, kernel
2.4.22, python 2.3.3 (GCC 3.3.2), and MySQL 4.0.18.

Regards,

. Facundo

Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
ADVERTENCIA.

La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley.
Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo.
Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada.
Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje.
Muchas Gracias.


get at bent

Jan 25, 2005, 5:35 PM

Post #6 of 16 (1121 views)
Permalink
Re: MySQLdb [In reply to]

> The problem I have is that it takes just over two minuted to execute the
> 3000 insert statements which seems really slow!

Are you creating a new DB connection for every insert?

I just did a test on my system (Athlon 2500+), 3000 rows with an
auto_increment field and a randomly generated 128 character field. 1.9
seconds.



--
http://mail.python.org/mailman/listinfo/python-list


get at bent

Jan 25, 2005, 11:59 PM

Post #7 of 16 (1125 views)
Permalink
Re: MySQLdb [In reply to]

> How many indices?

Just the primary key (id).



--
http://mail.python.org/mailman/listinfo/python-list


daniel at bowettsolutions

Jan 26, 2005, 12:27 AM

Post #8 of 16 (1123 views)
Permalink
Re: MySQLdb [In reply to]

Dennis Lee Bieber wrote:
> On Tue, 25 Jan 2005 20:43:54 +0000, Daniel Bowett
> <daniel [at] bowettsolutions> declaimed the following in
> comp.lang.python:
>
>
>>As a test I have written a script that executes 3000 insert statements
>>on a table. The table contains 10 fields with a mix of text and numbers
>>- its a product table for a website eg UPC, ProductName, Price etc.
>>
>
> How many indices?
>
>
>>The problem I have is that it takes just over two minuted to execute the
>>3000 insert statements which seems really slow! I am running it on a
>
>
> I recall reading that, for some RDBMs, when doing such batch
> inserts, they recommend turning off the indices at the start, do the
> inserts, then reactivate the indices -- apparently it is faster to
> rebuild an index after the data has been inserted, then to continually
> update the index.
>

UPC is my only index - its a varchar with 20 characters. I am only
opening the connection once, then doing 3000 execute statements in a for
loop.

I do have two "TEXT" fields in the table which contain the long and
short description. The average length of the long description is about
167 characters, the longest is 1800 characters. Is this whats making it
slow?

--
http://mail.python.org/mailman/listinfo/python-list


nobody at here

Jan 27, 2005, 12:34 PM

Post #9 of 16 (1109 views)
Permalink
Re: MySQLdb [In reply to]

Hi Daniel,

You should probably take a look at the executemany method of the cursor.
Your insert times might drop by a factor 20 . Here's an example.

Cheers,

Fedor

import time
import MySQLdb


db=MySQLdb.Connect(user="me",passwd="my password",db="test")
c=db.cursor()
n=0
tic=time.time()
for i in range(3000):
n+=c.execute('INSERT INTO testtable VALUES (%s)', (i,))
toc=time.time()
t1=toc-tic
print 'separate sql statements: %s, inserted %s records' % (t1,n)



tic=time.time()
n=c.executemany('INSERT INTO testtable VALUES (%s)', [(i,) for i in
range(3000)])
toc=time.time()
t2=toc-tic
print 'all at once %s inserted %s records' % (t2,n)

OUTPUT>>>
separate sql statements: 0.571248054504, inserted 3000 records
all at once 0.0253219604492 inserted 3000 records


--
http://mail.python.org/mailman/listinfo/python-list


gstoyanoff at yahoo

Jan 28, 2005, 7:03 AM

Post #10 of 16 (1105 views)
Permalink
Re: MySQLdb [In reply to]

Daniel Bowett wrote:

> Daniel Bowett wrote:
>> I have just started playing around with MySQLdb for a project I am
>> planning.
>>
>> As a test I have written a script that executes 3000 insert statements
>> on a table. The table contains 10 fields with a mix of text and numbers
>> - its a product table for a website eg UPC, ProductName, Price etc.
>>
>> The problem I have is that it takes just over two minuted to execute the
>> 3000 insert statements which seems really slow! I am running it on a
>> machine with a 1.5 Ghz Pentium M Processor and Gig Of Ram. I dont think
>> the machine is to blame for the speed because during execution the
>> processor sits at about 10% and there is loads of free RAM.
>>
>> Does anyone know if this sort of speed sounds right?
>>
>> Cheers,
>>
>> Dan.
>>
>>
>
> UPDATE
> ------
>
> I have found the "executemany" function! It now takes around a second to
> complete the 3000 inserts.
>
> Lesson learnt - I should have posted my code...
>
> Thanks for your help everyone.

Hi Daniel,

I was just wondering the executemany sends the insert as batch, does it?
That is what I was going to suggest for speed MySQL should process this
very quickly as a batch the problem was probably getting them there.

Regards,
George
--
http://mail.python.org/mailman/listinfo/python-list


skip at pobox

Apr 23, 2006, 7:05 PM

Post #11 of 16 (1028 views)
Permalink
Re: MySQLdb [In reply to]

placid> Does anyone have binary for MySQLdb (python 2.4.3, MySQL 5.0a) ?

Platform? Last I checked a few weeks ago, MySQLdb didn't yet work with
MySQL 5.0.

Skip
--
http://mail.python.org/mailman/listinfo/python-list


Bulkan at gmail

Apr 23, 2006, 8:15 PM

Post #12 of 16 (1027 views)
Permalink
Re: MySQLdb [In reply to]

skip [at] pobox wrote:

> placid> Does anyone have binary for MySQLdb (python 2.4.3, MySQL 5.0a) ?
>
> Platform? Last I checked a few weeks ago, MySQLdb didn't yet work with
> MySQL 5.0.
>
> Skip

Sorry about that , im using Windows XP...

--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

Jan 29, 2008, 8:30 AM

Post #13 of 16 (701 views)
Permalink
Re: MySQLdb [In reply to]

pavloutefkros [at] gmail wrote:

> hello,
> i have problem manipulating mySQL data. When i add values in a Table,
> i can recieve them instantly but when i check the table from another
> script, the new values dont exist.
>
> i'm not experienced in sql dbses so the problem might be something
> outside python.
>
> example (i do this to add values, and then i check and values have
> been added):
>
> ####################################################################
> import MySQLdb
> conn = MySQLdb.connect (host = 'localhost',
> user = 'root',
> passwd = 'MYPASHERE',
> db = 'test')
> cursor = conn.cursor ()
>
> cursor.execute ("""
> INSERT INTO testsignin (user, pass, secretcode)
> VALUES
> ('dkiauser', 'dkiapass', 'dkiacode'),
> ('gmtuser', 'gmtpass', 'gmtcode')
> """)
>
> print "Number of rows inserted: %d" % cursor.rowcount
>
> cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
> row = cursor.fetchone()
> print row
> ####################################################################
>
> but then when i try to get them from another script with this:
>
> ####################################################################
> import MySQLdb
> conn = MySQLdb.connect (host = 'localhost',
> user = 'root',
> passwd = 'MYPASHERE',
> db = 'test')
> cursor = conn.cursor ()
>
> cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
> row = cursor.fetchone()
> print row
> ####################################################################
>
> i get a None

You need to commit your changes, using

conn.commit()

after doing them.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


python.list at tim

Jan 29, 2008, 8:38 AM

Post #14 of 16 (701 views)
Permalink
Re: MySQLdb [In reply to]

> i have problem manipulating mySQL data. When i add values in a Table,
> i can recieve them instantly but when i check the table from another
> script, the new values dont exist.

Depending on your transaction settings (both on your mysql
connection object in code, and the engine used for the table(s)
in mysql's DB), you may have to commit your transaction to make
it visible in other connections. This helps prevent partial
transactions from being visible when they're in inconsistent states.

-tkc


--
http://mail.python.org/mailman/listinfo/python-list


geraldwalkerx at gmail

Nov 22, 2009, 7:00 AM

Post #15 of 16 (353 views)
Permalink
Re: MySQLdb [In reply to]

Kill Joy wrote:
> Hi all.
>
> I have a mod_python script with two query:
>
> cursor = db.cursor()
>
> sql = 'SELECT * FROM users where username=\'' + username +'\''
> cursor.execute(sql)
> result = cursor.fetchall()
> num = int(cursor.rowcount)
>
> if num == 0 :
> sql2 = 'insert into users values (null, \'' + username + '\', \'' +
> password +'\', \'no\',\'fdfdf\')'
> cursor.execute(sql2)
db.commit()
> warning = "Registration ok"
>
> else :
> warning = "EXIST!"
>
> The first query is executed... but not the second. It doesn't insert.
> Why?
> I'm a newbie... sorry.
>
> Many thanks.
>

I added db.commit() after cursor.execute(sql2).

--
http://mail.python.org/mailman/listinfo/python-list


g.ricioppo at gmail

Nov 22, 2009, 7:03 AM

Post #16 of 16 (353 views)
Permalink
Re: MySQLdb [In reply to]

On 22 Nov, 16:00, Gerald Walker <geraldwalk...@gmail.com> wrote:
> Kill Joy wrote:
> > Hi all.
>
> > I have a mod_python script with two query:
>
> >    cursor = db.cursor()
>
> >    sql = 'SELECT * FROM users where username=\'' + username +'\''
> >    cursor.execute(sql)
> >    result = cursor.fetchall()
> >    num =  int(cursor.rowcount)
>
> >    if num == 0 :
> >            sql2 = 'insert into users values (null, \'' + username + '\', \'' +
> > password +'\', \'no\',\'fdfdf\')'
> >            cursor.execute(sql2)
>
>                 db.commit()
>
> >            warning = "Registration ok"
>
> >    else :
> >            warning = "EXIST!"
>
> > The first query is executed... but not the second. It doesn't insert.
> > Why?
> > I'm a newbie... sorry.
>
> > Many thanks.
>
> I added db.commit() after cursor.execute(sql2).

ohhh... many thanks many thanks.

Gius.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.