mysql获取某个数据库的所有表名
select TABLE_NAME from information_schema.tables where TABLE_SCHEMA="your database name"
mysql获取某个表的所有字段名
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查询数据库中所有表及列的信息
SELECT
TABLE_NAME,
COLUMN_NAME,
DATA_TYPE,
COLUMN_COMMENT
FROM
INFORMATION_SCHEMA. COLUMNS
WHERE
TABLE_SCHEMA = '数据库名'