2008年5月8日 星期四

MySQL簡易操作

建立資料庫
mysql> create database accounting;

新增使用者以及其權限,當建立一位新使用者,我們必須授予他權限,什麼可以做,什麼不可以做。

MySQL存有三種類型的權限:
使用者權限

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • INDEX
  • ALTER
  • CREATE
  • DROP


管理者權限

  • RELOAD
  • SHUTDOWN
  • PROCESS
  • FILE

特別權限

  • ALL
  • USAGE

GRANT和REVOKE是用來授權或是取消使用者的權限

建立一個howard使用者,對於accounting資料庫具有select, insert, update, delete的權限
mysql> grant select, insert, update, delete
-> on accounting.*
-> to 'howard'@'localhost' identified by 'howardgogogo';


刪除howard使用者
mysql> delete from mysql.user
->where user='howard' and host='localhost';


在accounting資料庫新增一個資料表accounting
mysql> use accounting;
mysql> create table accouting (
->date date not null,
->account_type tinyint(1) unsigned not null,
->type tinyint(2) unsigned not null,
->description char(50) not null,
->amount int(10) unsigned not null
->);


可以用以下指令來看建立好的資料表:
show columns from accounting;

0 意見: