mysql table作成

自宅サーバーの温度とかの監視用
mysqlへ data保存させる予定ですが、その tableの作成に使ったコマンド

create table diskstats ( id int unsigned primary key not null auto_increment,datetime datetime,rootR MEDIUMINT Unsigned,rootW MEDIUMINT Unsigned,homeR MEDIUMINT Unsigned,homeW MEDIUMINT Unsigned,varR MEDIUMINT Unsigned,varW MEDIUMINT Unsigned,tmpR MEDIUMINT Unsigned,tmpW MEDIUMINT Unsigned,mysqlR MEDIUMINT Unsigned,mysqlW MEDIUMINT Unsigned) engine=MyISAM;
create table memory ( id int unsigned primary key not null auto_increment,datetime datetime,free MEDIUMINT unsigned,cache MEDIUMINT unsigned,used MEDIUMINT,kernel MEDIUMINT unsigned unsigned,swapfree MEDIUMINT unsigned unsigned) engine=MyISAM;
create table net ( id int unsigned primary key not null auto_increment,name varchar(10),datetime datetime,value BIGINT unsigned) engine=MyISAM;
create table df ( id int unsigned primary key not null auto_increment,datetime datetime,root smallint unsigned,home smallint unsigned,tmp smallint unsigned,var smallint unsigned,mysql smallint unsigned,MLC MEDIUMINT unsigned,s10k4 MEDIUMINT unsigned,MK3001 MEDIUMINT unsigned) engine=MyISAM;
create table smart ( id int unsigned primary key not null auto_increment,name varchar(10),datetime datetime,Temp TINYINT unsigned,Power MEDIUMINT unsigned,byteread FLOAT(10,3) unsigned,bytewrite FLOAT(10,3) unsigned,Id177 SMALLINT unsigned,Id178 SMALLINT unsigned,Id179 SMALLINT unsigned,Id180 SMALLINT unsigned,Id183 SMALLINT unsigned) engine=MyISAM;
create table power ( id int unsigned primary key not null auto_increment,datetime datetime,PowerOnTime FLOAT(10.1) unsigned) engine MyISAM;
create table sensors ( id int unsigned primary key not null auto_increment,datetime datetime,core0 TINYINT signed,core1 TINYINT signed,fan2 SMALLINT unsigned,fan3 SMALLINT unsigned,SYSTIN TINYINT signed,AUXTIN0 TINYINT signed) engine=MyISAM;
create table access ( id int unsigned primary key not null auto_increment,datetime datetime,access BIGINT unsigned) engine MyISAM;
create table diskN1 ( id int unsigned primary key not null auto_increment,name varchar(10),datetime datetime,value BIGINT unsigned) engine=MyISAM;
create table cpu ( id int unsigned primary key not null auto_increment,datetime datetime,cpuidle0 smallint Unsigned,cpuidle1 smallint Unsigned,cpuused0 smallint Unsigned,cpuused1 smallint Unsigned,cpusystem0 smallint Unsigned,cpusystem1 smallint Unsigned,cpuio0 smallint Unsigned,cpuio1 smallint Unsigned);

table内を細かく確認するのは、
describe table名;

更に詳しく確認するのは
show table status;

MySQLのテーブル

前作ったサーバーは、HotSaNICというツールを使って、
パソコンの温度とかをグラフ化していましたが、
今回は自作のスクリプト+MySQL+RRDTool
で行ってみようと思っています

MySQLは、手打ちで作業することって余り無いので、よく使うコマンド一覧

linuxのプロンプトから

mysqlに入るとき
mysql -u root

パスワード変えるとき (忘れたときとか)
mysqladmin -u root -p password

mysqlのプロンプトから

データーベース一覧を見るとき
show databases;

データーベースを変更するとき
use hogehoge;

テーブル名を見るとき
show tables;

詳しくテーブル名を見るとき
show table status;

MySQLのテーブルを作る時の書式
create table diskstats ( id int unsigned primary key not null auto_increment,name varchar(10),date date,time time,value bigint unsigned) engine=MyISAM;

テーブルの内容を表示
select * from diskstats where name=’varW’ order by id desc limit 50;

現在から 1時間前までの物だけを表示
select * from hoge where 日付時間型の列名 between date_add(now(),interval -1 hour) and now();