MySQL查看数据库内所有的表名、表备注、字段名称、字段类型、字段备注

1、单次查看表及字段备注

show full columns from 表名;

或者

show full fields from 表名;

 2、查看整个数据库内查看数据库内所有的表名、表备注、字段名称、字段类型、字段备注

select 	t.TABLE_NAME
			,t.TABLE_COMMENT
			,c.COLUMN_NAME
			,c.COLUMN_TYPE
			,c.COLUMN_COMMENT 
from 
information_schema.`COLUMNS` c 
,information_schema.`TABLES` t 
where 	 c.TABLE_NAME = t.TABLE_NAME
and		 t.TABLE_SCHEMA = 'database'  --更换为自己查询的数据库名称
;

或者

SELECT  
  COLUMN_NAME 列名,  
  COLUMN_TYPE 数据类型,  
    DATA_TYPE 字段类型,  
  CHARACTER_MAXIMUM_LENGTH 长度,  
  IS_NULLABLE 是否为空,  
  COLUMN_DEFAULT 默认值,  
  COLUMN_COMMENT 备注   
FROM  
 INFORMATION_SCHEMA.COLUMNS  
where  
-- developerclub为数据库名称,到时候只需要修改成你要导出表结构的数据库即可  
table_schema ='developerclub'  
AND  
-- article为表名,到时候换成你要导出的表的名称  

-- 如果不写的话,默认会查询出所有表中的数据,
-- 这样可能就分不清到底哪些字段是哪张表中的了,所以还是建议写上要导出的名名称。  
table_name  = 'article'  

或者

SELECT
    UPPER(column_name) AS '字段名称',
    column_comment AS '字段描述',
    UPPER(column_type) AS '字段类型',
    IF(column_key='PRI','TRUE','FALSE') AS '主键唯一',
    IF(IS_NULLABLE='NO','TRUE','FALSE') AS '非空'
FROM
    information_schema. COLUMNS
WHERE
    TABLE_SCHEMA = '数据库名称'
AND table_name = '表名';

 3、查看所有数据库、表

show databases;
show tables;

4、查看表结构

show create table Table.A;

5、查看表索引

SHOW INDEX FROM course;

6、查看数据库进程、停止某项

SHOW PROCESSLIST; 
KILL ID;
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用如下的SQL语句来获取dwd库中所有的信息: ``` SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = 'dwd' ``` 这个语句会返回dwd库中所有表名注释。 接下来,可以使用以下的SQL语句来获取每个字段名和字段注释: ``` SELECT column_name, column_comment FROM information_schema.columns WHERE table_schema = 'dwd' AND table_name = '表名' ``` 将上面的SQL语句中的“表名”替换成具体的表名,就可以获取该的所有字段名和字段注释。 如果需要将所有的信息都导出来,可以使用脚本来自动化执行以上的SQL查询,并将结果保存到文件中。以下是一个Python脚本的示例: ``` import pymysql # 连接数据库 db = pymysql.connect(host='localhost', user='root', password='密码', db='dwd') # 获取所有的信息 cursor = db.cursor() cursor.execute("SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = 'dwd'") tables = cursor.fetchall() # 获取每个字段信息并输出到文件 with open('output.txt', 'w', encoding='utf-8') as f: for table in tables: table_name = table[0] table_comment = table[1] f.write(f'Table Name: {table_name}\nTable Comment: {table_comment}\n') cursor.execute(f"SELECT column_name, column_comment FROM information_schema.columns WHERE table_schema = 'dwd' AND table_name = '{table_name}'") columns = cursor.fetchall() for column in columns: column_name = column[0] column_comment = column[1] f.write(f'Column Name: {column_name}\nColumn Comment: {column_comment}\n') f.write('\n') # 关闭数据库连接 db.close() ``` 这个脚本会将所有的信息输出到一个名为“output.txt”的文件中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值