MySql 獲取表的欄位名

2021-07-22 16:00:39 字數 1450 閱讀 7523

show databases                                //列出 mysql server 資料庫。

show tables [from db_name] //列出資料庫資料表。

show create tables tbl_name //匯出資料表結構。

show table status [from db_name] //列出資料表及表狀態資訊。

show columns from tbl_name [from db_name] //列出資料表字段

show fields from tbl_name [from db_name],describe tbl_name [col_name]。

show full columns from tbl_name [from db_name]//列出欄位及詳情

show full fields from tbl_name [from db_name] //列出字段完整屬性

show index from tbl_name [from db_name] //列出表索引。

show status //列出 db server 狀態。

show variables //列出 mysql 系統環境變數。

show processlist //列出執行命令。

show grants for user //列出某使用者許可權

mysql安裝成功後可以看到已經存在mysql、information_schema和test這個幾個資料庫,information_schema庫中有乙個名為columns的表,這個表中記錄了資料庫中所有表的字段資訊。知道這個表後,獲取任意表的字段就只需要一條select語句即可。例如:

select column_name from information_schema.columns where table_name = 'your_table_name';

上述的做法有一點問題,如果多個資料庫中存在你想要查詢的表名,那麼查詢的結果會包括全部的字段資訊。通過desc information_schema.columns可以看到該表中列名為table_schema是記錄資料庫名,因此下面的寫法更為嚴格

select column_name from information_schema.columns where table_name = 'your_table_name' and table_schema = 'your_db_name';

mysql獲取某個表的所有欄位名

mysql安裝成功後可以看到已經存在mysql information schema和test這個幾個資料庫,information schema庫中有乙個名為columns的表,這個表中記錄了資料庫中所有表的字段資訊。知道這個表後,獲取任意表的字段就只需要一條select語句即可。例如 selec...

mysql獲取某個表的所有欄位名

mysql安裝成功後可以看到已經存在mysql information schema和test這個幾個資料庫,information schema庫中有乙個名為columns的表,這個表中記錄了資料庫中所有表的字段資訊。知道這個表後,獲取任意表的字段就只需要一條select語句即可。例如 selec...

mysql獲取某個表的所有欄位名

mysql安裝成功後可以看到已經存在mysql information schema和test這個幾個資料庫。information schema庫中有乙個名為columns的表,這個表中記錄了資料庫中所有表的字段資訊。知道這個表後,獲取任意表的字段就只需要一條select語句即可。例如 selec...