| 2.1 เข้า MySQL โดยพิมพ์ password ผ่าน command prompt 2.2 ดูสถานะของ MySQL
 2.3 สร้างผู้ใช้อื่นนอกจาก root อีก 3 users
 2.4 แสดงรายชื่อผู้ใช้ที่สามารถเข้า MySQL
 2.5 สร้างตาราง และลบตาราง
 2.6 เรียกใช้ฐานข้อมูล test และสร้างตารางชื่อ orderm, orderd, pro, cust
 2.7 เพิ่มระเบียนใหม่ใน 4 ตาราง
 2.8 สร้างฐานข้อมูลใหม่ชื่อ a และ b พร้อม user ใหม่ชื่อ a และ b
 2.9 คัดลอกทุกตารางจากฐานข้อมูล test ใส่ในฐานข้อมูล b
 2.10 สร้าง user และ ฐานข้อมูลใหม่ ให้นักเรียนแต่ละคน
 2.11 ลบสมาชิกออกจากระบบ 1 คน
 2.1 เข้า MySQL โดยพิมพ์ password ผ่าน command prompt
 C:\mysql\bin>mysql -u root -p
 Enter password: ************
 Welcome to the MySQL monitor.
 Your MySQL connection id is 6
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 mysql> exit
 C:\mysql\bin>mysql -u root -pyourpassword
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 7 to server version: 3.23.57
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 mysql>
 
 
 2.2 ดูสถานะของ MySQL
 mysql> status
 --------------
 C:\mysql\bin\mysql.EXE  Ver 11.15 Distrib 3.23.44, for Win95/Win98 (i32)
 Connection id:          2
 Current database:       test
 Current user:           root@localhost
 Server version:         3.23.44
 Protocol version:       10
 Connection:             localhost via TCP/IP
 Client characterset:    latin1
 Server characterset:    latin1
 TCP port:               3306
 Uptime:                 20 min 18 sec
 Threads: 2 Questions: 145 Slow queries: 0 Opens: 9 Flush tables: 1
 Open tales: 3 Queries per second avg: 0.119
 --------------
 mysql>
 
 
 2.3 สร้างผู้ใช้อื่นนอกจาก root อีก 3 users
 burin เป็น full superuser เข้า server จากที่ไหนก็ได้ และกำหนดรหัสผ่านเป็น some_pass
 admin เข้าจัดการกับฐานข้อมูล จาก localhost ไม่ต้องใช้รหัสผ่าน สามารถ reload หรือ process งานเกี่ยวกับ admin ได้
 tom เข้าจัดการกับฐานข้อมูล จาก localhost ไม่ต้องใช้รหัสผ่าน สามารถจัดการกับฐานข้อมูล dtom ได้เต็มที่
 dummy เข้าไม่ต้องใช้รหัสผ่าน จาก localhost แต่ไม่มีสิทธิใด ๆ เพราะมีแผนจะกำหนดสิทธิให้กับ database ที่เหมาะสมภายหลัง
 mysql> grant all privileges on *.* TO burin@localhost
 IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
 mysql> grant all privileges on *.* TO burin@"%"
 IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
 mysql> grant all privileges on dtom.* TO dtom@localhost;
 mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
 mysql> GRANT USAGE ON *.* TO dummy@localhost;
 mysql> FLUSH PRIVILEGES;
 
 อ.อิทธิพล แซ่จิว ใช้เว็บเพจนี้ เสริมการสอนเรื่องฐานข้อมูล .. ผมจึงต้องปรับปรุงให้เหมาะสม
2.4 แสดงรายชื่อผู้ใช้ที่สามารถเข้า MySQL
 mysql> use MySQL;
 Database changed
 mysql> select user,password from user;
 | user | password         |
 | root | 606718756665bfe6 |
 | u    | 606718756665bfe6 |
 2 rows in set (0.00 sec)
 mysql>
 
 
 2.5 สร้างตาราง และลบตาราง
 mysql> use test;
 mysql> create table x(x int primary key);
 mysql> drop table x;
 mysql> drop table if exists x;
 
 แสดง Data type ของการใช้ phpmyadmin 25 แบบ ส่งเข้า SQL แล้วใช้ได้ทันที
 mysql> create table `samtable` (
 `f01` varchar(5) not null default '',
 `f02` tinyint(5) not null default '0',
 `f03` text not null,
 `f04` date not null default '0000-00-00',
 `f05` smallint(5) not null default '0',
 `f06` mediumint(5) not null default '0',
 `f07` int(5) not null default '0',
 `f08` bigint(5) not null default '0',
 `f09` float(5,2) not null default '0.00',
 `f10` double(5,2) not null default '0.00',
 `f11` decimal(5,0) not null default '0',
 `f12` datetime not null default '0000-00-00 00:00:00',
 `f13` timestamp(14) not null,
 `f14` time not null default '00:00:00',
 `f15` year(4) not null default '0000',
 `f16` varchar(5) not null default '',
 `f17` tinyblob not null,
 `f18` tinytext not null,
 `f19` blob not null,
 `f20` mediumblob not null,
 `f21` mediumtext not null,
 `f22` longblob not null,
 `f23` longtext not null,
 `f24` enum('0','1','2') not null default '0',
 `f25` set('M','F') not null default ''
 ) TYPE=MyISAM;
 
 
 2.6 เรียกใช้ฐานข้อมูล test และสร้างตารางชื่อ orderm, orderd, pro, cust
 mysql> use test;
 mysql> create table orderm(orderid int primary key,cust int,orderdate date,ordertime time);
 mysql> create table orderd(orderid int not null,pro int not null,primary key(orderid,pro));
 mysql> create table pro(pro int primary key,proname varchar(50),price double,prorest int);
 mysql> create table cust(cust int primary key,custname varchar(50));
 
  ฐานข้อมูลนี้ print screen มาจาก http://www.thaiall.com/teachaccess/db4order.mdb
 orderm : คำว่า m ย่อมาจาก main หมายถึง ข้อมูลการสั่งซื้อของแต่ละใบ ถ้ามี 3 ใบ ก็จะมี 3 ระเบียนในตารางนี้
 orderd : คำว่า d ย่อมาจาก detail หมายถึง ข้อมูลรายละเอียดการสั่งซื้อ เช่นใบสั่ง 3 ใบ อาจสั่งสินค้า 6 รายการ แฟ้มนี้อาจมี 6 ระเบียน
 pro : คำว่า pro ย่อมาจาก product หมายถึง ข้อมูลจำนวนสินค้า อาจมีสินค้าเป็น 1000 รายการ แฟ้มนี้ก็จะเก็บ 1000 ระเบียน
 cust : คำว่า cust ย่อมาจาก customer หมายถึง ข้อมูลจำนวนลูกค้า อาจมีลูกค้าเป็น 1000 รายการ แฟ้มนี้ก็จะเก็บ 1000 ระเบียน
 
 2.7 เพิ่มระเบียนใหม่ใน 4 ตาราง
 mysql> use test;
 mysql> insert into `orderm` (`orderid`,`cust`,`orderdate`,`ordertime`)values(
 '1001','101','1/7/2004','13:35');
 mysql> insert into orderm values('1002','101','1/7/2004','13:35');
 mysql> insert into orderm values(1003,103,'15/7/2004','10:12');
 mysql> insert into orderd values(1001,201,5,10);
 mysql> insert into orderd values(1001,202,6,100);
 mysql> insert into orderd values(1001,203,1,30);
 mysql> insert into orderd values(1002,204,3,50);
 mysql> insert into orderd values(1003,202,4,50);
 mysql> insert into orderd values(1003,204,1,50);
 mysql> insert into pro values(201,'pen',10,200);
 mysql> insert into pro values(202,'book',100,10);
 mysql> insert into pro values(203,'ink',30,5);
 mysql> insert into pro values(204,'knight',50,20)
mysql> insert into cust values(101,'Mr.Boy');
 mysql> insert into cust values(102,'Ms.Girl');
 mysql> insert into cust values(103,'Mr.Man');
 
 
 2.8 สร้างฐานข้อมูลใหม่ชื่อ a และ b พร้อม user ใหม่ชื่อ a และ b
 mysql> show databases;
 mysql> create database a;
 mysql> create database b;
 mysql> GRANT USAGE ON *.* TO a@localhost;
 mysql> grant all privileges on b.* TO 'b'@'localhost' identified by 'bpassword';
 mysql> exit
 user ชื่อ a และ b เข้าฐานข้อมูลใด ๆ ไม่ได้เลย ถ้าไม่กำหนดฐานข้อมูลให้กับ user นั้นโดยเฉพาะ
 ตัวอย่างนี้ user a เข้า MySQL โดยไม่มีรหัสผ่านก็ได้ แต่ไม่สามารถจัดการข้อมูลในฐานข้อมูลใด ๆ ได้
 สำหรับ user b เป็นเจ้าของฐานข้อมูล b โดยสมบูรณ์ และมีรหัสผ่านเข้า MySQL คือ bpassword
 ถ้าไม่มีสิทธิ แต่พยายามใช้ฐานข้อมูลนั้น ก็จะถูกปฏิเสธ ดังตัวอย่างด้านล่าง
 mysql> use a;
 ERROR 1044: Access denied for user: 'a@localhost' to database 'a'
 
 2.9 คัดลอกทุกตารางจากฐานข้อมูล test ใส่ในฐานข้อมูล b
 1. ใช้ explorer copy แฟ้มทุกแฟ้มในห้อง c:\mysql\data\test\*.* ไปไว้ในห้อง c:\mysql\data\b\*.*
 2. เท่านี้ก็เรียบร้อย ข้อมูลทั้งหมดในฐานข้อมูล test เป็นของ b แล้วครับ
 2.10 สร้าง user และ ฐานข้อมูลใหม่ ให้นักเรียนแต่ละคน|  | ผม zip แฟ้มทั้ง 15 แฟ้ม ของ 5 ตาราง ไว้ในแฟ้ม 5table.zip [4 KB]
 ตาราง : cust
 ตาราง : pro
 ตาราง : orderm
 ตาราง : orderd
 ตาราง : wow
 ถ้าท่านมีฐานข้อมูลชื่อ xxx และอยากมีตาราง 5 ตารางนี้
 ท่านก็คลาย zip ลงไปในห้อง c:\mysql\data\xxx ก็เรียบร้อย
 ประหยัดเวลาสร้างตารางอีก 5 ตาราง ตามที่ผมทำให้ดูนี้
 | 
 mysql> show databases;
 mysql> grant all privileges on s01.* TO 's01'@'%' identified by 's01';
 mysql> grant all privileges on s02.* TO 's02'@'%' identified by 's02';
 ::
 ::
 mysql> grant all privileges on s30.* TO 's30'@'%' identified by 's30';
 mysql> exit
 สร้างสมาชิกใหม่ 30 สมาชิก แต่ตอนสร้าง database ชื่อ s01 ถึง s30
 ให้ใช้ explorer copy ห้องต้นแบบ เป็นห้องต่าง ๆ ไว้ใน c:\mysql\data\s01 ถึง c:\mysql\data\s30
 ผลการสร้างสมาชิก s01 จะเพิ่มระเบียนในแฟ้ม user และ db ของ ฐานข้อมูลชื่อ MySQL
 ส่วนรหัสผ่าน จะเหมือนกับชื่อ user เช่นสมาชิกชื่อ s01 ก็จะมีรหัสผ่านคือ s01
 สมาชิกใหม่สามารถเขียนโปรแกรมไว้ใน server ใดก็ได้ เพราะอนุญาตไว้ว่าเข้ามาจากที่ใดก็ได้ ไม่จำกัดเฉพาะ localhost
 
 2.11 ลบสมาชิกออกจากระบบ 1 คน
 mysql> delete from `user` where `User` = "s01" and `Host` = "%";
 mysql> delete from `db` where `User` = "s01" and `Host` = "%";
 mysql> delete from `tables_priv` where `User` = "s01" and `Host` = "%";
 mysql> delete from `columns_priv` where `User` = "s01" and `Host` = "%";
 # ปรับปรุงสิทธิเข้าถึงใหม่อีกรอบ ...
 mysql> flush privileges ;
 mysql>
 คำสั่งเหล่านี้ copy มาจาก phpMyAdmin ในส่วนของการลบสมาชิก ถ้าสมาชิกคนนี้ถูกสร้างขึ้นมาด้วยคำสั่งข้างล่างนี้
 grant all privileges on s01.* TO 's01'@'%' identified by 's01';
 |