Newbie matter: MySQL connection

Andrew Lusk alusk at uiuc.edu
Mon Dec 16 19:06:52 EST 2002


"Juan Ignacio Chiapetta" <juanimaster at ciudad.com.ar> writes:

> Hi everyone, I'm just starting with Python and I want to connect to a MySQL
> database. I'm using mysql-python-0.9.2 on Windows XP, with Python 2.2 and
> MySQL 3.23.38
> I can't get Python to connect to my database, here's the problem. If I
> import CompatMysqldb, I try to use the Connection() method, but I get this
> response:
>
> Traceback (most recent call last):
>   File "<pyshell#23>", line 1, in ?
>     conexion=CompatMysqldb.Connection('host', 'user','pass', 'dbname')
>   File "C:\Python22\Lib\site-packages\CompatMysqldb.py", line 117, in
> __init__
>     self.__transactional = self.__conn.server_capabilities &
> CLIENT.TRANSACTIONS
> AttributeError: server_capabilities
>

I personally use MySQLdb, rather than CompactMySQLdb( which I confess
I haven't heard of).  With MySQLdb the syntax is:

connection = 
MySQLdb.connect(db="foodb",user="fooman",passwd="abc",host="foo.com")

cursor = connection.cursor()

num_rows = cursor.execute("SELECT ...")

etc.

--Andrew



More information about the Python-list mailing list