การสร้าง Database ขึ้นใหม่ด้วยคำสั่ง CREATE
  ในกรณีการสร้าง Database สามารถใช้คำสั่งในการสร้างด้วยคำสั่ง CREATE DATABASE  ซึ่งการสร้าง Database นั้นทำได้ง่าย มาดูกัน
Syntax
ให้ทำการตรวจสอบฐานข้อมูลที่มีอยู่ในระบบด้วยคำสั่ง
แล้วทำการแสดง Database ทั้งหมดดูอีกครั้งเพื่อตรวจสอบว่าถูกสร้างขึ้นจริงหรือไม่
คำสั่งในแบบ command line แบบชัดกัน
Syntax
| CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification] ... create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name | 
ให้ทำการตรวจสอบฐานข้อมูลที่มีอยู่ในระบบด้วยคำสั่ง
| show databases; | 
จะปรากฏชื่อ database ที่มีอยู่ในระบบทั้งหมดดังรูป
 เราจะทำการสร้างฐานข้อมูลขึ่นใหม่ชื่อ mydb  ด้วยคำสั่ง ดังนี้
| CREATE DATABASE mydb; | 
แล้วทำการแสดง Database ทั้งหมดดูอีกครั้งเพื่อตรวจสอบว่าถูกสร้างขึ้นจริงหรือไม่
คำสั่งในแบบ command line แบบชัดกัน
| C:\>cd "Program Files\MariaDB 10.1\bin" C:\Program Files\MariaDB 10.1\bin>mysql -u root -p Enter password: ******** Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.1.14-MariaDB mariadb.org binary distribution Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +---------------------------------+ | Database | +---------------------------------+ | information_schema | | mysql | | performance_schema | | test | +---------------------------------+ 4 rows in set (0.00 sec) MariaDB [(none)]> CREATE DATABASE mydb; Query OK, 1 row affected (0.04 sec) MariaDB [(none)]> show databases; +--------------------------------+ | Database | +--------------------------------+ | information_schema | | mydb | | mysql | | performance_schema | | test | +---------------------------------+ 5 rows in set (0.00 sec) MariaDB [(none)]> | 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Post a Comment