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?
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?
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.
_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.
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.