// 以 jlu 登入,並使用資料庫 eric
mysql -u jlu -p eric
// 如果要登入遠端 hostname 的 MySQL Server
mysql -h hostname -u jlu -p eric
// 如果 jlu 不喜歡或者想更改 root 指定的密碼,可以執行以下指令
// 同樣的,newpassword 指的是你想輸入的密碼
set password for jlu@localhost=password('newpassword');
// create table create table Product ( ID int, Name varchar(30), Price decimal(5,2), Qty int); // 查看 Product 是否已經產生 // Windows 版產生的 table 名稱變成 product show tables;
insert into Product values (1, 'Monitor', 200.5, 4); insert into Product values(2, '無線存取器', 110, 3); insert into Product values(3, '無線滑鼠', 11.99, 10); insert into Product values(4, '無線輸入超值組合包', 111.99, 8); // 資料新增之後,檢查一下輸入是否正確 select * from Product;
// 查詢所有的產品名稱以及數量 select Name, Qty from Product; // 查詢所有價格高於 100 的產品 select * from Product where Price > 100; // 查詢編號為 3 的產品名稱以及價格 select Name, Price from Product where ID = 3; // 修改編號 3 的產品價格,並利用前一個查詢指令來確認 update Product set Price=15.3 where ID=3; // 將編號 3 的產品刪除 delete from Product where ID=3;