Skip to content

MySQL database connector for Python (with Python 3 support)

License

Notifications You must be signed in to change notification settings

axiros/gevent_mysqldb

 
 

Repository files navigation

gevent_mysqldb

This is a fork of mysqlclient to support gevent. The purpose is to get the speed of a mysql C-library within a gevent application, but without the need to use a thread-pool.

This is achieved by modifying mysql.c to use the non blocking API of libmariadb. This API allows to customize the waiting for read/write events on a socket. gevent_mysql uses gevent.socket.wait_read and gevent.socket.wait_write to do so.

Known Limitations

  • The destructor for a _mysql.Connection does not happen in a non-blocking way when the connection is still open. In that case the destructor calls implicitly mysql_close() wich cannot be done in gevent friendly way. Since switching a greenlet in the code path of garbage collection is dangerous. Image the garbage collection is run by the hub greenlet. Then the hub would switch to himself, which is not possible. Recommendation: Call conn.close() always explicitly.

  • The destructor of _mysql.result could block other greenlets under the following circumstances.

    • The result object was acquired via conn.use_result().
    • Not all rows from the result have been read by the application.

    conn.use_result() gives a lazy result back. In case the application did not consume all rows from this result the mysql-driver has to discard the remaining rows. This discard (and all the involved network IO) does not happen in a non-blocking way. Recommendation is to use conn.store_result(). This applies also for MySQLdb.SSCursor and MySQLdb.CursorUseResultMixIn, because the use conn.use_result() under the hood.

mysqlclient

This project is a fork of MySQLdb1. This project adds Python 3 support and fixed many bugs.

Support

Do Not use Github Issue Tracker to ask help. OSS Maintainer is not free tech support

When your question looks relating to Python rather than MySQL:

Or when you have question about MySQL:

Install

Windows

gevent_mysqldb hasn't been tested/build on windows yet.

If binary wheels do not exist for your version of Python, it may be possible to build from source, but if this does not work, do not come asking for support. To build from source, download the MariaDB C Connector and install it. It must be installed in the default location (usually "C:\Program Files\MariaDB\MariaDB Connector C" or "C:\Program Files (x86)\MariaDB\MariaDB Connector C" for 32-bit). If you build the connector yourself or install it in a different location, set the environment variable MYSQLCLIENT_CONNECTOR before installing. Once you have the connector installed and an appropriate version of Visual Studio for your version of Python:

$ pip install mysqlclient

macOS (Homebrew)

gevent_mysqldb hasn't been tested/build on macOS yet.

Linux

Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don't file a issue on the issue tracker.

You may need to install the Python 3 and libmariadb development headers and libraries

Debian / Ubuntu

sudo apt-get install python3-setuptools python3-dev build-essential python3-gevent libmariadb-dev-compat

Fedora

sudo dnf install python3-setuptools python3-devel python3-gevent gcc-c++ mariadb-connector-c-devel

RedHat 8 / CentOS 8

sudo yum install python3-setuptools python3-devel python3-gevent gcc-c++ mariadb-connector-c-devel mariadb-devel

Then you can install gevent_mysqldb via pip now:

pip3 install git+https://github.com/axiros/gevent_mysqldb.git

Customize build (POSIX)

mysqlclient uses mysql_config or mariadb_config by default for finding compiler/linker flags.

You can use MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables to customize compiler/linker options.

$ export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags`
$ export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`
$ pip install mysqlclient

Documentation

Documentation is hosted on Read The Docs

About

MySQL database connector for Python (with Python 3 support)

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 63.8%
  • C 33.4%
  • C++ 2.7%
  • Makefile 0.1%