MySQL: 2007年11月アーカイブ
今回はMySQLでデータベースとテーブル作成
以下3つのデータベースを作成する
(ただ、_testはどのように使うかよくわからなかったので、_developmentと_productionだけ作りました)
■データベースを作成
■テーブルを作成、カテゴリ(プロジェクト)とタスク
タスクを纏めるカテゴリのようなもの(ここではプロジェクト)テーブルとタスクそのもののテーブルを作成する。
■railsアプリケーションの設定ファイル(DB設定と文字コート)を編集
mytask/config/database.yml を編集
mytask/config/environment.rbに文字コード追加
以下3つのデータベースを作成する
(ただ、_testはどのように使うかよくわからなかったので、_developmentと_productionだけ作りました)
■データベースを作成
- mytask_development
mytask_test- mytask_production
mysql> create database mytask_development;
mysql> create database mytask_production;
mysql> grant all on mytask_development.* to username@localhost identified by 'password';
mysql> grant all on mytask_production.* to username@localhost identified by 'password';
■テーブルを作成、カテゴリ(プロジェクト)とタスク
タスクを纏めるカテゴリのようなもの(ここではプロジェクト)テーブルとタスクそのもののテーブルを作成する。
create table projects (
id int unsigned auto_increment,
name varchar(128) not null,
content varchar(255),
task_count int default 0,
status enum('close','open') default 'close',
created_at timestamp,
updated_at timestamp,
limited_at timestamp,
primary key (id),
index status_idx (status)
);
create table tasks (
id int unsigned auto_increment,
project_id int unsigned not null,
name varchar(128) not null,
content text,
status enum('yet', 'exec', 'finish') default 'yet',
created_at timestamp,
updated_at timestamp,
limited_at timestamp,
primary key (id),
index project_id_idx (project_id),
index status_idx (status)
);
■railsアプリケーションの設定ファイル(DB設定と文字コート)を編集
mytask/config/database.yml を編集
development: adapter: mysql database: mytask_development username: username password: password socket: /var/lib/mysql/mysql.sock encoding: utf8
mytask/config/environment.rbに文字コード追加
#KCODE = 'u' # Be sure to restart your web server when you modify this file.

