An mysql-python tutorial?

D

Dfenestr8

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?
 
K

Kartic

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_Side/Python/PythonMySQL/PythonMySQL.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
 
E

EuGeNe

A

Andy Dustman

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

Dfenestr8

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:
"[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/04/17/mysql_in_mandrake_91.html
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top