What’s the difference between MySQLdb, mysqlclient and MySQL connector/Python?

MySQLdb is a thin python wrapper around C module which implements API for MySQL database. There was MySQLDb1 version of wrapper used some time ago and now it is considered to be a legacy. As MySQLDb1 started evolving to MySQLDb2 with bug fixes and Python3 support, a MySQLDb1 was forked and here is how mysqlclient … Read more

Dynamic SQL Queries with Python and mySQL

Databases have different notations for “quoting” identifiers (table and column names etc) and values (data). MySQL uses backticks to quote identifiers. For values, it’s best to use the parameter substitution mechanism provided by the connector package: it’s more likely to handle tricky cases like embedded quotes correctly, and will reduce the risk of SQL injection. … Read more

Why MYSQL IN keyword not considering NULL values

This : Error not in (‘Timeout’,’Connection Error’); is semantically equivalent to: Error <> ‘TimeOut’ AND Error <> ‘Connection Error’ Rules about null comparison applies to IN too. So if the value of Error is NULL, the database can’t make the expression true. To fix, you could do this: COALESCE(Error,”) not in (‘Timeout’,’Connection Error’); Or better … Read more

Can’t install mysql-python (newer versions) in Windows

I solved it myself. I use the wheel installer from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python. There are two wheel packages there. The amd64 one refuses to install on my platform (Windows) but the other one works just fine. I mean the file with this name: MySQL_python-1.2.5-cp27-none-win32.whl Then install it by running this below command in the same folder with … Read more

Python and MySQLdb: substitution of table resulting in syntax error

Parameter substitution in the DB API is only for values – not tables or fields. You’ll need to use normal string substitution for those: selectQ =”””SELECT * FROM %s WHERE %s = %%s;””” % (self.table,self.columnSpecName) self.db.execute(selectQ,(idKey,)) return self.db.store_result() Note that the value placeholder has a double % – this is so that it’s left alone … Read more