MySQL-drivers (Python)

Uit De Vliegende Brigade
(Doorverwezen vanaf MySQL-driver (Python))
Ga naar: navigatie, zoeken

Inventaris

Er bestaan diverse MySQL-drivers. Welke is goed genoeg? Waarom dit geen non-issue is: Installatie wil maar niet goed lukken. Vandaar dat het de moeite waard is, om effe wat langer bij deze vraag stil te staan.

Ik wil SQLAlchemy gebruiken als ORB. Deze voorbeeldcode laat zien welke drivers in ieder geval ondersteund worden (ik kan me trouwens goed voorstellen dat het driver-onafhankelijk is):

# MySQLdb
engine = create_engine('mysql://scott:tiger@localhost/foo')

# mysql-python
engine = create_engine('mysql+mysqldb://scott:tiger@localhost/foo')

# MySQL-connector-python
engine = create_engine('mysql+mysqlconnector://scott:tiger@localhost/foo')

# OurSQL
engine = create_engine('mysql+oursql://scott:tiger@localhost/foo')

MySQLdb

MySQL-Connector-Python

  • Veelbelovend, 100% Python (dus bv. geen C-bibliotheken), en afkomstig van Oracle zelf
  • Python 3.x wordt ondersteund
  • "MySQL-connector-Python is a pure Python MySQL driver, and is now released under the auspices of the MySQL project itself, as owned by Oracle. MySQL-connector-Python supports both Python 3 as well as eventlet monkeypatching, and is well maintained. It is endorsed by Oracle as the official Oracle-supported driver for MySQL, so to that extent, it is in most ways Openstack's first choice in driver. However, Oracle refuses to publish MySQL-connector-Python on Pypi, which is critical to the Openstack infrastructure. Repeated attempts to communicate with Oracle in order to resolve this issue have not made any progress. Therefore, for this one unfortunate reason, MySQL-connector-Python will not have a place in the Openstack ecosystem unless this issue is resolved" [2]
  • "The problem with using Oracle's Connector/Python is that it has subtle bugs and other integration issues. It's easy to install, but nearly impossible to get to work for all the real-world use cases I've tried it for. Hence why I always recommend MySQLdb" [3]
  • https://dev.mysql.com/downloads/connector/python/ MySQL Connector/Python

mysqlclient

MySQL-Python

PyMySQL

  • Geschikt voor Python 3.x
  • Dit zou de opvolger zijn van MySQLdb
  • "PyMySQL is a pure Python MySQL driver, first written as a rough port of the MySQL-Python driver. PyMySQL meets all of Openstack's criterion for a driver: it is fully open source, hosted on Github, released on Pypi, is actively maintained, is written in pure Python so is eventlet-monkeypatch compatible, and is fully Python 3 compatible. As this document is named "PyMySQL Evaluation", it should be apparent that this is the driver Openstack is currently leaning towards; because it is the only one that meets all criteria fully, it is already most likely the "winner". However, it does have some minor code quality issues which hopefully can be addressed in some way; the section below titled "PyMySQL Code Review" will summarize the current state of the code. " [7]
  • https://github.com/PyMySQL/PyMySQL

OurSQL

Storm

https://storm.canonical.com

Selectie

Wanneer heb ik wat gekozen? En waarom?

MySQL-Connector-Python (okt. 2018)

Er is een interessante discussie over wat de beste driver is. Die discussie lijkt zich toe te spitsen op Mysqlclient vs. MySQL-Connector-Python [10], [11] - Ik kies deze laatste.

Shortlist jan. 2019

Deze ondersteunen allemaal Python 3.x en hebben geen 'grote tekortkomingen':

  • mysqlclient
  • MySQL-Connector-Python
  • PyMySQL

Installatie MySQL-Connector (okt. 2018 - Python 2.x)

  • Downloaden naar buroblad
  • Dubbelklikken
  • Installeren
  • Klaar.

Installatie mysqlclient (jan. 2019 - 3.x - Niet gelukt)

[12]:

sudo apt install python3-dev   # OK
sudo apt install default-libmysqlclient-dev   # Package kon niet gevonden worden

pip install mysqlclient   # Pakket niet gevonden
cd /home/strompf/.local/bin & sudo ./pip install mysqlclient   # Pakket niet gevonden
sudo apt install mysqlclient   # Niet gevonden

Installatie MySQL-Connector-Python (jan. 2019 - 3.x)

[13]:

Download: Ah, de eerste versie is waarschijnlijk voor Python 3 → Gedwonload naar buroblad
Installatie: Gewoon dubbelklikken - Inderdaad Python 3 → Klaar
Bestanden

Zie ook

Bronnen