$ django-admin.py startproject mysite
このプロジェクト用のデータベースmysite_dbと、
このデータベースにアクセスするユーザmysite_userを作成。
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql> create database mysite_db;
Query OK, 1 row affected (0.00 sec)
mysql> grant CREATE,ALTER,DROP,INDEX,SELECT,UPDATE,INSERT,DELETE
-> on mysite_db.*
-> to mysite_user@localhost
-> identified by 'mysite_pass';
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
$
プロジェクトの設定ファイルsettings.pyに作成したデータベースの情報を書き込む。
$ cd mysite/
$ vi mysite/settings.py
...
ENGINE = django.db.backends.mysql
NAME = mysite_db
USER = mysite_user
PASWORD= mysite_pass
...
$
syncdbコマンドでデータベースを初期化。
$ ./manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'xxx'): root
Email address: hoge@example.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
$
初期化されたデータベースの中身を確認。
$ mysql -u root -p
Enter password:
...
mysql> use mysite_db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_mysite_db |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_content_type |
| django_session |
| django_site |
+----------------------------+
9 rows in set (0.00 sec)
mysql> desc auth_user;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| password | varchar(128) | NO | | NULL | |
| last_login | datetime | NO | | NULL | |
| is_superuser | tinyint(1) | NO | | NULL | |
| username | varchar(30) | NO | UNI | NULL | |
| first_name | varchar(30) | NO | | NULL | |
| last_name | varchar(30) | NO | | NULL | |
| email | varchar(75) | NO | | NULL | |
| is_staff | tinyint(1) | NO | | NULL | |
| is_active | tinyint(1) | NO | | NULL | |
| date_joined | datetime | NO | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)
mysql> select username,email from auth_user;
+----------+------------------+
| username | email |
+----------+------------------+
| root | hoge@example.com |
+----------+------------------+
1 row in set (0.00 sec)
mysql>
0 件のコメント:
コメントを投稿