User:Alvonruff/Notes on MySQLdb

From ISFDB
Jump to navigation Jump to search

It turns out MySQLdb has has moved along. There are several revisions and forks of MySQLdb1, which is the legacy version intended for python2, and there is MySQLdb2, which is the new version for python3. But MySQLdb1 is outdated and unsupported, and MySQLdb2 is not ready for production use.

  • MySQLdb1 - This can be found at https://github.com/farcepest/MySQLdb1. The latest version is 1.2.4, but it is 10 years old. This is intended for machines still using python2. There is an ancient ten-year old TODO to support Python 2.7-3.3, which my installation is beyond. Installation method:
  • MySQLdb2 - This is a fork of MySQLdb1. Also absolete. This has the same character set issues of MySQLdb1. Installation: sudo pip2 install mysqlclient. This version of MySQLdb has two relevant optional arguments when connecting: use_unicode and charset:
    • use_unicode. The proper format would be use_unicode=True. This is supposed to cause MySQLdb to return unicode characters instead of bytes. This doesn't seem to change any visible behaviors, and the code defaults to False on python2 and True on python3.
    • charset. The proper format would be charset='target_charset', where valid charsets are:
      • utf8mb4 - generates an ascii encoding exception
      • utf8mb3 - generates an ascii encoding exception
      • latin1 - generates an ascii encoding exception
      • koi8r - generates ? in place of the target character.
      • koi8u - generates ? in place of the target character.
  • moist - This is a fork of MySQLdb2, which was refactored such that it requires at least Python-2.7 and compatible with Python-3.x (whatever that means). It also warns that :i "is not yet ready for prime-time". I haven't tried this as yet.
  • MySQL Connector - MySQL has released their own module called MySQL Connector. This is clearly the correct API to use, as it is the only officially support Python API right now. However, the current version only works on Python3, and requires rewriting all of the ISFDB database access code. According to their compatibility chart, Connector release 8.0 can work with MySQL 8.0 and python2.7, but only before connector release 8.0.24. Initial attempts at installing 8.0.23 were unsuccessful, failing the dependency checks. The latest release can be installed with:
    • sudo pip3 install mysql-connector-python