Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > An mysql-python tutorial?

Reply
Thread Tools

An mysql-python tutorial?

 
 
Dfenestr8
Guest
Posts: n/a
 
      01-28-2005
Hi.

Been told by the admin of my (free!) server that he'd rather I should
learn to use mysql if I want to continue writing cgi scripts there.

Not even sure exactly what mysql is.

Is there a simple tutorial anywhere on the web about using python + mysql?
 
Reply With Quote
 
 
 
 
Kartic
Guest
Posts: n/a
 
      01-29-2005
Dfenestr8 said the following on 1/28/2005 5:21 PM:
> Hi.
>
> Been told by the admin of my (free!) server that he'd rather I should
> learn to use mysql if I want to continue writing cgi scripts there.
>
> Not even sure exactly what mysql is.
>
> Is there a simple tutorial anywhere on the web about using python + mysql?


Did you try googling?

There are two items in the very first page that should be of use to you.
One is the Python-MySQL module, which you should have installed.

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

There is an examples directory that has some concrete stuff to help you
learn.

Another hit is a basic tutorial, simple to follow and learn :-
http://images.devshed.com/Server_Sid...ythonMySQL.pdf

And here is one more site, good stuff here too:-
http://www.kitebird.com/articles/pydbapi.html

You might also want to check the "Charming Python" pages at IBM.com but
I dont know if they have articles covering mysql.

HTH!

Thanks,
--Kartic
 
Reply With Quote
 
 
 
 
EuGeNe
Guest
Posts: n/a
 
      01-29-2005
Dfenestr8 wrote:
> Hi.
>
> Been told by the admin of my (free!) server that he'd rather I should
> learn to use mysql if I want to continue writing cgi scripts there.
>
> Not even sure exactly what mysql is.
>
> Is there a simple tutorial anywhere on the web about using python + mysql?


http://www.devshed.com/c/a/Python/My...y-With-Python/

that one put me on the right track (I think

--
EuGeNe

[----
www.boardkulture.com
www.actiphot.com
www.xsbar.com
----]
 
Reply With Quote
 
Andy Dustman
Guest
Posts: n/a
 
      01-29-2005
It's a pretty good tutorial, thought I would recommend you forget about
the fetchone() example. The example below demonstrates three additional
features that will make your life easier: MySQL option files, tuple
unpacking, and cursors as iterators (fourth feature: the default host
is localhost; this is rapidly turning into the Spanish Inquisition
sketch):

#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(db="db56a", read_default_file="~/.my.cnf")
cursor = db.cursor()
cursor.execute("SELECT name, species FROM animals")
for name, species in cursor:
print name, "-->", species

(I also shy away from doing SELECT *; what if your schema changes?)
(If the indentation is hosed, blame Google Groups.)

 
Reply With Quote
 
Dfenestr8
Guest
Posts: n/a
 
      01-29-2005
On Sat, 29 Jan 2005 06:41:37 +0000, Kartic wrote:

[snip]
> And here is one more site, good stuff here too:-
> http://www.kitebird.com/articles/pydbapi.html
>


Hi.

I followed the instructions there, tried out the test script they
recommend.

Can you tell me why this command, in the python interpreter:

>>>conn = MySQLdb.connect (host = "localhost", user = "flipper", passwd =

"[hidden]", db = "mydb")

produces this error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 63, in Connect
return apply(Connection, args, kwargs)
File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 115, in __init__
self._make_connection(args, kwargs2)
File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 41, in _make_connection
apply(super(ConnectionBase, self).__init__, args, kwargs)
_mysql_exceptions.OperationalError: (1045, "Access denied for user:
'flipper@localhost' (Using password: YES)")

I also have MySQL installed, and tried setting up the user flipper with
the mysql client, as per the instructions here:
http://vsbabu.org/mt/archives/2003/0...ndrake_91.html
 
Reply With Quote
 
Andy Dustman
Guest
Posts: n/a
 
      01-30-2005
It definitely looks like an access control problem; recheck your grants.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57