Why use _mysql module and not use MySQLdb directly?

Chris Angelico rosuav at gmail.com
Sat Feb 8 10:00:58 CET 2014

On Sat, Feb 8, 2014 at 7:52 PM, Sam <lightaiyee at gmail.com> wrote:
> I am writing my first python script to access MySQL database. With reference to http://mysql-python.sourceforge.net/MySQLdb.html#connection-objects
> Why is it advisable to use _mysql and not MySQLdb module directly?

Other way around. It's advisable to ignore _mysql, which is a fairly
direct representation of the MySQL C API, and use MySQLdb instead.
When you use MySQLdb, you can fairly easily switch over to another
database engine (like PostgreSQL, which for most purposes is superior
to MySQL anyway), without changing most of your code. The only reason
to use _mysql would be if you need your code to be really similar to
other MySQL code in some other language - maybe you're using Python to
prototype a C application, and want to keep everything as close as you
can. Normally, use the higher level module.


More information about the Python-list mailing list