Baby Steps with Django - part 2 database setup

So I introduced this series seven months ago, oops! Oh well, let's get started.

Before we get anywhere, we need to have some kind of database. The main ones we that care about right now are mysql, postgres and sqlite. At this stage in the game, it really makes no difference. I am going to use mysql because I am most familiar with it.

Get the database:

On Ubuntu:

sudo apt-get install mysql-server python-mysqldb

When asked, make up a new mysql admin password.

On Gentoo:

Run each of the following commands, where [version] is the version of mysql and new-password is your new mysql admin password.

emerge mysql mysql-python

emerge --config =dev-db/mysql-[version]

/etc/init.d/mysql start

/usr/bin/mysqladmin -u root -h localhost password 'new-password'

Create a new database and user

Login to the database, you need to enter the password that you just chose:

mysql -u root -p

Now you are at the mysql prompt that looks like this - mysql>

Enter the following line to create a new database:

CREATE DATABASE djtest;

Enter the following line to create a new database user, feel free to change the last word "password" to something else:

GRANT ALL ON djtest.* TO 'djangouser'@'localhost' IDENTIFIED BY 'password';

Enter the following line to quit mysql:

quit

Database Conclusion

Now we have four values that we can later use for our settings.py file

> DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'djtest' DATABASE_USER = 'djangouser' DATABASE_PASSWORD = 'password'

We have not actually done any Django yet, just the dull system admin tasks that are required. So let's get Django.

Installing Django

On Ubuntu:

sudo apt-get install python-django

On Gentoo:

emerge -vp django

On Gentoo: Make sure you have at least the mysql use flag turned on, you probably also want bash-completion and examples. Then when you are happy emerge django

Discuss this post - Leave a comment

4 thoughts on “Baby Steps with Django - part 2 database setup

  1. <p>Where has the world gone to that Zeth started to write things that are so
    simple they shouldn't be mentioned on a blog that write goodies?</p>

  2. <p>I know, for people who make websites, knowing how to use mysql is easy,
    however, it is otherwise not required knowledge.</p>

  3. <p>SELECT * FROM django_site WHERE id=1;</p>
    <p>update django_site set name='commandline.org.uk' WHERE id=1;
    update django_site set domain='commandline.org.uk' WHERE id=1;</p>

  4. Hi, i&#39;m new member in this blog , i&#39;m interested Django but @ my country has little people can answer .
    <br/>and i&#39;m not good English Language. when i think this problem.
    <br/>i&#39; m want ask in the step Database setup @ Django in commandline . i can&#39;t create database , i don&#39;t understand how is edit settings.py
    <br/>
    <br/>
    <br/><img src="/static/forum/img/smilies/sad.png">
    <br/>

How about Global Thermonuclear War? Wouldn't you prefer a good game of chess? Powered by zpress