Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

การดูข้อมูล MySQL Databases และ Tables

User อาจลืม database/table name, table structure, column names MySQL มี statements ให้ข้อมูลเหล่านี้

'SHOW DATABASES' แสดง databases ทั้งหมดที่ server จัดการ ดู database ปัจจุบัน用 'DATABASE()' function

Query

mysql> SELECT DATABASE();

Output

+---------------------+
| DATABASE()          |
+---------------------+
| databaseInUse       |
+---------------------+

ห้าไม่ได้ select database จะได้ 'NULL'

ดู tables ใน default database:

Query

mysql> SHOW TABLES;

Output

+-----------------------------------+
| Tables_in_databaseInUse           |
+-----------------------------------+
| val1                              |
| val2                              |
+-----------------------------------+

Column name ใน output: 'Tables_in_databaseInUse' (databaseInUse = selected database name)

ดู table structure ใช้ 'DESCRIBE' statement แสดงข้อมูลทุกคอลัมน์:

Query

mysql> DESCRIBE pet;

Output

+---------+-------------+-------+------+-----------+--------+
| Field   | Type        | Null  | Key  | Default   | Extra  |
+---------+-------------+-------+------+-----------+--------+
| name    | varchar(20) | YES   |      | NULL      |        |
| owner   | varchar(20) | YES   |      | NULL      |        |
+---------+-------------+-------+------+-----------+--------+

Field = column name, Type = data type, Null = NULL allowed?, Key = indexed?, Default = default value, Extra = special info (เช่น auto_increment)