masayuki5160's diary

名古屋でエンジニアしてます。

MySQL起動から初期設定めも

MySQL起動
#/etc/init.d/mysqld.d start

MySQLのコンソールにログイン
※rootユーザとしてログイン
#mysql -u root

データベース作成
#create database masa;

データベースを扱うユーザの作成
#grant all on *.* to user@localhost identified by 'password';
すべてのMySQLデータベースに対して(*.*のとこ)、
「ユーザ名:user、パスワード:password」(user@localhost identified by 'password'のところ)でアクセスできるようになる。

#grant all on masa.* to user@localhost identified by 'password';
masaを扱うユーザuserをパスワード:passwordと設定。


データベースの一覧表示
#show databases;

データベースの指定
#use masa;
※masaはデータベース名

データベースにテーブルを作成する
#create table bbs (
id int(5) unsigned NOT NULL auto_increment,
name varchar(40) NOT NULL,
body text NOT NULL,
ctime datetime NOT NULL,
PRIMARY KEY (id) );


テーブルの情報を表示
#desc users;
※テーブルusersの情報を表示


また思いついたりしたら追記していこ。


参考
MySQLコマンド(DB, table, カラム操作)まとめ
http://tech.bayashi.jp/archives/entry/server/2009/002487.html