2008年12月2日 星期二

MySQL基本操作

在使用command line操作時的使用方法

使用下方指令進入mysql用戶端
>mysql -u root -p
按 Enter
Password:
輸入你的 mysql 密碼。


一、建立資料庫
mysql> create database temp;
按 Enter

建立名為 temp 的資料庫。

二、列出所有資料庫
mysql> show databases;
按 Enter

就會列出這台 MySQL 主機中,所有的資料庫名稱。

三、選擇要使用的資料庫:

在 mysql 提示,輸入:
mysql> use temp;
按 Enter

四、建立資料表:
在mysql>下輸入:
CREATE TABLE `member` (
`mem_id` int(11) NOT NULL auto_increment,
`account` varchar(25) NOT NULL,
`password` varchar(32) NOT NULL,
PRIMARY KEY (`mem_id`)
) ENGINE=MyISAM DEFAULT CHARSET=big5 AUTO_INCREMENT=1;

按 Enter
MySQL 就會在現在所選用的資料庫,產生一個 member 資料表。


五、秀出資料表的欄位資料:
mysql> show columns from temp;
or
mysql> describe temp;

按 Enter

六、刪除資料表:
mysql> drop table Test;
按 Enter

MySQL 就會刪除 Test 資料表。

七、刪除資料庫:
mysql> drop database temp;
按 Enter

MySQL 就會刪除 temp 資料庫。

八、匯入sql檔案
mysql> source ;

九、經由外部的方式匯入或匯出資料庫
備份 SQL data:
>mysqldump -u 使用者名稱 -p –default-character-set=utf8 資料庫名稱 > temp.sql

匯入 SQL data:
>mysql -u 使用者名稱 -p 資料庫名稱 < temp.sql

沒有留言:

張貼留言