select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name';
上述的作法有一點問題,若是多個數據庫中存在你想要查詢的表名,那麼查詢的結果會包括所有的字段信息。經過DESC information_schema.COLUMNS能夠看到該表中列名爲TABLE_SCHEMA是記錄數據庫名,所以下面的寫法更爲嚴格sql
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name';