RkBlog

Hardware, programming and astronomy tutorials and reviews.

Using memSQL and MariaDB in Django projects

Using new and interesting database server with Django

memSQL

memSQL is a new database engine offering high efficiency thanks to RAM oriented data storage design and query compilation (check the FAQ). It's not related to MySQL but it offers a MySQL compatible client - that allows quick and easy way to check it.

Download the database package and follow the instructions given on the page. When you extract the database you can check system requirements:

./check_system
And if there are no critical problems you can start the memSQL server with:
./memsqld --port 3307

Server is working on port 3307. MySQL by default will be on 3306. To connect to the memSQL server you can do this:

mysql -u root -h 127.0.0.1 -P 3307 --prompt="memsql> "
You can create a test database - "CREATE DATABASE test;".

memSQL and Django

There is no memSQL backend for Django (yet), but to some extent the MySQL backend may be used. Database configuration would look like so:

DEBUG = False
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '3307',
    }
}

DEBUG needs to be turned off to avoid exceptions on "mysql" warnings (and we will get some on syncdb like: "Feature 'REFERENCES' is not supported by MemSQL. Execution will continue, but the feature will be ignored."). The database configuration has the port and host pointing it to the memSQL and not to the local MySQL server.

If you have a MySQL 5.0.3 or newer and recent Django version you will have to disable SAVEPOINT usage by Django MySQL backend (You will get "Feature 'SAVEPOINT' is not supported by MemSQL" exception with memSQL). Do disable it edit Django backend code django/db/backends/mysql/base.py and find:

self.features.uses_savepoints =                 self.get_server_version() >= (5, 0, 3)
Set it to False:
self.features.uses_savepoints = False
Now syncdb, fixtures loading and most/all queries should work. I've tested memSQL with my blog applications and everything seems to be working. I didn't compared performance as there aren't any complex queries that could make a difference.

memSQL may be an interesting solution for some web applications having problems with database scalability. Using the mysql backend can be handy for some tests, but usage in production environments would rather require dedicated backend for memsql.

MariaDB

MariaDB is a MySQL fork, binary compatible with it. This database server can be used as a drop in replacement for MySQL. The difference is in some extra features and extra storage engines added to MariaDB. You can check documentation to find out more. No backend hacking is required in this case.

RkBlog

Django web framework tutorials, 1 July 2012,

Comment article