4

So, here is a question:

How to deploy Mezzanine, a Django CMS, locally with MySQL instead of default SQLite?

What is the exact recipe?

3

Script in one piece is in ->here

1. Python

Python is preinstalled in Ubuntu and AFAIK it's vital to some system/desktop-env operations, but just in case:

sudo apt-get install python
sudo apt-get install python-pip
sudo apt-get install build-essential python-dev

2. MySQL

You need to install (a)server, (b)client, (c)dev libs & headers, (d)python adapter

sudo apt-get install mysql-server
sudo apt-get install mysql-client-5.5
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-mysqldb

3. Credentials

Establish MySQL credentials, tutorial on this is ->here, so that you have the following users with corresponding login commands:

  • root user

    mysql -u root -p / password 
    
  • Mezzanine user

    mysql -u mezz -p / masterkey 
    

4. Install Mezzanine

pip install mezzanine

5. Create Project

mezzanine-project myproject
cd myproject

6. Configure db to MySQL

Use your credentials from step 3.

vim local_settings.py

That's a Python file. DATABASES variable should be made to be like this (use your credentials at italicized places):

DATABASES = {
    "default": {
        # Ends with "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".
        "ENGINE": "django.db.backends.mysql",
        # DB name or path to database file if using sqlite3.
        "NAME": "myproject",
        # Not used with sqlite3.
        "USER": "mezz",
        # Not used with sqlite3.
        "PASSWORD": "masterkey",
        # Set to empty string for localhost. Not used with sqlite3.
        "HOST": "",
        # Set to empty string for default. Not used with sqlite3.
        "PORT": "",
    }
}

7. Do Mezzanine routines

Collect static files and templates

python manage.py collectstatic  
python manage.py collecttemplates  

Synchronize with database. This step depends on the Django version, at the time of writing this, Django 1.7 is still not supported, so use syncdb:

python manage.py syncdb

You may also consifer using South migration manager, but know that South project is at it's dusk since Django 1.7 has new migration system.

After syncdb output you'd have a superuser (for entering Mezzanine's admin section). You can create superuser separately after sync:

python manage.py createsuperuser

Run built-in server of Mezzanine (more concretely, it's Django's lightweight server):

python manage.py runserver

8. Go

Point your browser at http://127.0.0.1:8000 and hopefully you'll see the Mezzanine standard greeting.

9. Production Deployment

->Here is a good guide, you can use it to create a demo site in production environment (on that particular site it's free with some limits). And here are their settings for MySQL.

10. Extras

11. 'Revisions'

Some revisions I gathered on my way:

  • South migration manager needs some change in Database section of your settings.py
  • Mezzanine and versioning seemed very frustrating to me: it doesn't support django 1.7, and on my hosting provider there was no root access, so I should have installed MySQL-Python ('adapter') through pip. Some versions of adapter-mezzanine-django are incompatible.

For now, I use Mezzanine v3.1.10, Django v1.6.10 and MySQL-Python v1.2.3 and it works. I disabled South backend addon, because it made things for my deployment more complex rather than simpler.

12. Postscript

If someone advises me about how to improve this guide, I will do it. j-D

  • Thanks for edits. I feel very confused now. j-D (feel free to del this comment, didn't know how to respond elsewhere). – sdd Jan 16 '15 at 23:25
  • thx, @karel, all fine. you're the best j-D – sdd Jan 17 '15 at 19:18
  • How come we do not need the manage.py createdb --noinput step? – 0xF2 Dec 29 '16 at 4:01
  • To create a database for the project one can use this command: CREATE DATABASE myproject; – aless80 Jul 9 '18 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.