Connecting Tech Pros Worldwide Help | Site Map

An mysql-python tutorial?

Dfenestr8
Guest
 
Posts: n/a
#1: Jul 18 '05
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?
Kartic
Guest
 
Posts: n/a
#2: Jul 18 '05

re: An mysql-python tutorial?


Dfenestr8 said the following on 1/28/2005 5:21 PM:[color=blue]
> 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?[/color]

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
EuGeNe
Guest
 
Posts: n/a
#3: Jul 18 '05

re: An mysql-python tutorial?


Dfenestr8 wrote:[color=blue]
> 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?[/color]

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
----]
Andy Dustman
Guest
 
Posts: n/a
#4: Jul 18 '05

re: An mysql-python tutorial?


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.)

Dfenestr8
Guest
 
Posts: n/a
#5: Jul 18 '05

re: An mysql-python tutorial?


On Sat, 29 Jan 2005 06:41:37 +0000, Kartic wrote:

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

Hi.

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

Can you tell me why this command, in the python interpreter:
[color=blue][color=green][color=darkred]
>>>conn = MySQLdb.connect (host = "localhost", user = "flipper", passwd =[/color][/color][/color]
"[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
Andy Dustman
Guest
 
Posts: n/a
#6: Jul 18 '05

re: An mysql-python tutorial?


It definitely looks like an access control problem; recheck your grants.

Closed Thread