という話

技術ブログにしたい

【メモ】MySQLのあれこれ

インフラエンジニアさんとかいれば任せられるんですがね。
プログラマなのでたまにしか使わないから忘れちゃうMySQLのあれこれの備忘録。

ユーザー作成
grant select on *.* to "username"@"localhost" identified by "password";

権限はMySQLリファレンスを参考



ユーザー確認
select Host, User from mysql.user;
ユーザー権限確認
show grants for "username"@"localhost";
インデックス追加

テーブル作成時

create table test_tabel (
  id int not null primary key,
  title varchar(255) default null,
  index index_name(title)
);
インデックス確認
show index from test_table; 
期間を指定してのデータを取得

1週間以内のデータ

select * from test_table where created_at >= now() - interval 7 day;


1ヶ月分(ログ出力したいときとか)

select * from test_table where created_at between '2013-12-01' and '2013-12-31';






SQL苦手だけど、アクセスが増えた時とかにまず初めにネックになるのが大体SQLなのでもっと勉強しなきゃなーと思う今日このごろ