tags:

views:

181

answers:

3

Two libraries for Mysql. I've always used _mysql because it's simpler.

Can anyone tell me the difference, and why I should use which one in certain occasions?

+8  A: 

MySQLdb uses DB-API (described in PEP 249) which should be preferred, since it's common to all database drivers. IMHO there is no advantage in going low-level with _mysql. I'd rather think of using higher level libraries, like SQLAlchemy, instead.

PiotrLegnica
`_mysql` needs to exist to connect the higher level api to the C libraries. The `_` should be a clue that you usually shouldn't use it.
gnibbler
unrelated. Nice cat.
Stefano Borini
+2  A: 

_mysql is the one-to-one mapping of the rough mysql API. On top of it, the DB-API is built, handling things using cursors and so on.

If you are used to the low-level mysql API provided by libmysqlclient, then the _mysql module is what you need, but as another answer says, there's no real need to go so low-level. You can work with the DB-API and behave just fine, with the added benefit that the DB-API is backend-independent.

Stefano Borini
+1  A: 

Alternatively, you can use MySQL Connector/Python:

MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. This means you don't have to compile anything or MySQL doesn't even have to be installed on the machine.

LenZ