DBA技术分享(九)- MySQL数据库中查找最常用的数据类型
csdh11 2025-01-02 15:31 35 浏览
一、概述
今天分享几个关于MySQL数据类型的查询,具体如下:
- 在 MySQL 数据库中查找最常用的数据类型
- 查找 MySQL 数据库中的所有数字列
- 查找 MySQL 数据库中的所有字符串(字符)列
- 查找 MySQL 数据库中的所有日期和时间列
- 查找 MySQL 数据库中的所有枚举列
- 查找 MySQL 数据库中的所有空间数据列
- 查找 MySQL 数据库中的所有 JSON 数据列
- 在 MySQL 数据库中查找大对象 (LOB) 数据类型列
- 在 MySQL 数据库中查找具有大对象 (LOB) 数据类型列的表
二、相关SQL
2.1 在 MySQL 数据库中查找最常用的数据类型
select data_type,
count(*) as columns,
cast(100*count(*)/sum_all.columns as decimal(36,2))
as percent_columns,
count(distinct concat(col.table_schema, '.', col.table_name))
as tables,
cast(100*count(distinct concat(col.table_schema,'.',col.table_name))
/ sum_all.tables as decimal(36,2)) as percent_tables
from information_schema.columns col
join (select count(distinct concat(c.table_schema, '.', c.table_name))
as tables,
count(*) as columns
from information_schema.columns c
join information_schema.tables t
on c.table_schema = t.table_schema
and c.table_name = t.table_name
where t.table_schema not in ('information_schema', 'mysql',
'performance_schema', 'sys')
and t.table_type = 'BASE TABLE'
) sum_all on true
join information_schema.tables tab
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
where tab.table_schema not in ('information_schema', 'mysql',
'performance_schema', 'sys')
and tab.table_type = 'BASE TABLE'
group by data_type,
sum_all.columns,
sum_all.tables
order by columns desc;
说明:
- data_type - 没有长度或精度的内置或用户数据类型,例如 int、varchar 或 datetime
- columns - 具有此数据类型的数据库(模式)中的列数
- percent_columns - 具有此数据类型的列的百分比。行总数为 100%
- tables- 数据库(模式)中具有此数据类型的表数
- percent_tables - 具有此数据类型的列的表的百分比。
2.2 查找 MySQL 数据库中的所有数字列
select col.table_schema as database_name,
col.table_name,
col.ordinal_position as col_id,
col.column_name,
col.data_type,
col.numeric_precision,
col.numeric_scale
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
and tab.table_name = col.table_name
and tab.table_type = 'BASE TABLE'
where col.data_type in ('tinyint', 'smallint', 'mediumint',
'int', 'bigint', 'decimal', 'bit',
'float', 'double')
and col.table_schema not in ('information_schema', 'sys',
'performance_schema', 'mysql')
--and col.table_schema = 'database_name' -- put your database name here
order by col.table_schema,
col.table_name,
col.ordinal_position;
说明:
- database_name - 数据库的名称(模式)
- table_name - 表的名称
- column_id - 表中的列位置
- column_name - 列的名称
- data_type - 数据类型
- numeric_precision - 列的精度
- numeric_scale - 列的比例
2.3 查找 MySQL 数据库中的所有字符串(字符)列
select col.table_schema as database_name,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type,
col.character_maximum_length as maximum_length,
col.character_set_name
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
and tab.table_name = col.table_name
and tab.table_type = 'BASE TABLE'
where col.data_type in ('char', 'varchar', 'binary', 'varbinary',
'blob', 'tinyblob', 'mediumblob', 'longblob',
'text', 'tinytext', 'mediumtext', 'longtext'
'enum', 'set')
and col.table_schema not in ('information_schema', 'sys',
'performance_schema', 'mysql')
--and col.table_schema = 'database_name' -- put your database name here
order by col.table_schema,
col.table_name,
col.ordinal_position;
说明:
- database_name - 数据库的名称(模式)
- table_name - 表的名称
- column_id - 表中的列位置
- column_name - 列的名称
- data_type - 数据类型
- maximum_length - 字符的最大长度
- character_set_name - 字符集名称
2.4 查找 MySQL 数据库中的所有日期和时间列
select col.table_schema as database_name,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type,
col.datetime_precision
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
and tab.table_name = col.table_name
and tab.table_type = 'BASE TABLE'
where col.data_type in ('date', 'time', 'datetime', 'year', 'timestamp')
and col.table_schema not in ('information_schema', 'sys',
'performance_schema', 'mysql')
--and col.table_schema = 'database_name' -- put your database name here
order by col.table_schema,
col.table_name,
col.ordinal_position;
说明:
- database_name - 数据库的名称(模式)
- table_name - 表的名称
- column_id - 表中的列位置
- column_name - 列的名称
- data_type - 数据类型
- datetime_precision - 小数秒精度
2.5 查找 MySQL 数据库中的所有枚举列
select col.table_schema as database_name,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type,
trim(leading 'enum' from col.column_type) as enum_values
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
and tab.table_name = col.table_name
and tab.table_type = 'BASE TABLE'
where col.data_type in ('enum')
and col.table_schema not in ('information_schema', 'sys',
'performance_schema', 'mysql')
--and col.table_schema = 'database_name' -- put your database name here
order by col.table_schema,
col.table_name,
col.ordinal_position;
说明:
- database_name - 数据库的名称(模式)
- table_name - 表的名称
- column_id - 表中的列位置
- column_name - 列的名称
- data_type - 数据类型
- enum_values - 声明可能的枚举值
2.6 查找 MySQL 数据库中的所有空间数据列
select col.table_schema as database_name,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type,
col.is_nullable
from information_schema.columns col
join information_schema.tables tab
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
and table_type = 'BASE TABLE'
where col.data_type in ('geometry', 'point', 'linestring', 'polygon',
'multipoint', 'multilinestring', 'multipolygon',
'geometrycollection')
and col.table_schema not in ('information_schema', 'sys',
'performance_schema', 'mysql')
-- and table_schema = 'database_name' -- put your database name here
order by col.table_schema,
col.table_name;
说明:
- database_name - 数据库的名称(模式)
- table_name - 表的名称
- column_id - 表中的列位置
- column_name - 列的名称
- data_type - 空间数据的类型:
(1)GEOMETRY
(2)POINT
(3)LINESTRING
(4)POLYGON
(5)MULTIPOINT
(6)MULTILINESTRING
(7)MULTIPOLYGON
(8)GEOMETRYCOLLECTION
- is_nullable - 指示列是否可以包含空值
2.7 查找 MySQL 数据库中的所有 JSON 数据列
select col.table_schema as database_name,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
and tab.table_name = col.table_name
and tab.table_type = 'BASE TABLE'
where col.data_type in ('json')
and col.table_schema not in ('information_schema', 'sys',
'performance_schema', 'mysql')
--and col.table_schema = 'database_name' -- put your database name here
order by col.table_schema,
col.table_name,
col.ordinal_position;
说明:
- database_name - 数据库的名称(模式)
- table_name - 表的名称
- column_id - 表中的列位置
- column_name - 列的名称
- data_type - 数据类型
2.8 在 MySQL 数据库中查找大对象 (LOB) 数据类型列
select tab.table_schema as database_name,
tab.table_name,
col.column_name,
col.data_type
from information_schema.tables as tab
inner join information_schema.columns as col
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
where tab.table_schema = 'your database name'
and tab.table_type = 'BASE TABLE'
and col.data_type in ('blob', 'mediumblob', 'longblob',
'text','mediumtext','longtext')
order by tab.table_name,
col.column_name;
说明:
- schema_name - 数据库的名称(模式)
- table_name - 表的名称
- column_name - 列的名称
- data_type - 数据类型
2.9 在 MySQL 数据库中查找具有大对象 (LOB) 数据类型列的表
select tab.table_name,
count(*) as columns
from information_schema.tables as tab
inner join information_schema.columns as col
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
and col.data_type in ('blob', 'mediumblob', 'longblob',
'text', 'mediumtext', 'longtext')
where tab.table_schema = 'your database name'
and tab.table_type = 'BASE TABLE'
group by tab.table_name
order by tab.table_name;
说明:
- table_name - 表的名称
- columns - 表中的 LOB 列数
小结
后面会分享更多Linux和DBA方面内容,感兴趣的朋友可以关注下!
相关推荐
- SpringBoot+LayUI后台管理系统开发脚手架
-
源码获取方式:关注,转发之后私信回复【源码】即可免费获取到!项目简介本项目本着避免重复造轮子的原则,建立一套快速开发JavaWEB项目(springboot-mini),能满足大部分后台管理系统基础开...
- Spring Boot+Vue全栈开发实战,中文版高清PDF资源
-
SpringBoot+Vue全栈开发实战,中文高清PDF资源,需要的可以私我:)SpringBoot致力于简化开发配置并为企业级开发提供一系列非业务性功能,而Vue则采用数据驱动视图的方式将程序...
- 2021年超详细的java学习路线总结—纯干货分享
-
本文整理了java开发的学习路线和相关的学习资源,非常适合零基础入门java的同学,希望大家在学习的时候,能够节省时间。纯干货,良心推荐!第一阶段:Java基础...
- 探秘Spring Cache:让Java应用飞起来的秘密武器
-
探秘SpringCache:让Java应用飞起来的秘密武器在当今快节奏的软件开发环境中,性能优化显得尤为重要。SpringCache作为Spring框架的一部分,为我们提供了强大的缓存管理能力,让...
- 3,从零开始搭建SSHM开发框架(集成Spring MVC)
-
目录本专题博客已共享在(这个可能会更新的稍微一些)https://code.csdn.net/yangwei19680827/maven_sshm_blog...
- Spring Boot中如何使用缓存?超简单
-
SpringBoot中的缓存可以减少从数据库重复获取数据或执行昂贵计算的需要,从而显著提高应用程序的性能。SpringBoot提供了与各种缓存提供程序的集成,您可以在应用程序中轻松配置和使用缓...
- 我敢保证,全网没有再比这更详细的Java知识点总结了,送你啊
-
接下来你看到的将是全网最详细的Java知识点总结,全文分为三大部分:Java基础、Java框架、Java+云数据小编将为大家仔细讲解每大部分里面的详细知识点,别眨眼,从小白到大佬、零基础到精通,你绝...
- 1,从零开始搭建SSHM开发框架(环境准备)
-
目录本专题博客已共享在https://code.csdn.net/yangwei19680827/maven_sshm_blog1,从零开始搭建SSHM开发框架(环境准备)...
- 做一个适合二次开发的低代码平台,把程序员从curd中解脱出来-1
-
干程序员也有好长时间了,大多数时间都是在做curd。现在想做一个通用的curd平台直接将我们解放出来;把核心放在业务处理中。用过代码生成器,在数据表设计好之后使用它就可以生成需要的controller...
- 设计一个高性能Java Web框架(java做网站的框架)
-
设计一个高性能JavaWeb框架在当今互联网高速发展的时代,构建高性能的JavaWeb框架对于提升用户体验至关重要。本文将从多个角度探讨如何设计这样一个框架,让我们一起进入这段充满挑战和乐趣的旅程...
- 【推荐】强&牛!一款开源免费的功能强大的代码生成器系统!
-
今天,给大家推荐一个代码生成器系统项目,这个项目目前收获了5.3KStar,个人觉得不错,值得拿出来和大家分享下。这是我目前见过最好的代码生成器系统项目。功能完整,代码结构清晰。...
- Java面试题及答案总结(2025版持续更新)
-
大家好,我是Java面试分享最近很多小伙伴在忙着找工作,给大家整理了一份非常全面的Java面试场景题及答案。...
- Java开发网站架构演变过程-从单体应用到微服务架构详解
-
Java开发网站架构演变过程,到目前为止,大致分为5个阶段,分别为单体架构、集群架构、分布式架构、SOA架构和微服务架构。下面玄武老师来给大家详细介绍下这5种架构模式的发展背景、各自优缺点以及涉及到的...
- 本地缓存GuavaCache(一)(guava本地缓存原理)
-
在并发量、吞吐量越来越大的情况下往往是离不开缓存的,使用缓存能减轻数据库的压力,临时存储数据。根据不同的场景选择不同的缓存,分布式缓存有Redis,Memcached、Tair、EVCache、Aer...
- 一周热门
- 最近发表
- 标签列表
-
- mydisktest_v298 (34)
- document.appendchild (35)
- 头像打包下载 (61)
- acmecadconverter_8.52绿色版 (39)
- word文档批量处理大师破解版 (36)
- server2016安装密钥 (33)
- mysql 昨天的日期 (37)
- parsevideo (33)
- 个人网站源码 (37)
- centos7.4下载 (33)
- mysql 查询今天的数据 (34)
- intouch2014r2sp1永久授权 (36)
- 先锋影音源资2019 (35)
- jdk1.8.0_191下载 (33)
- axure9注册码 (33)
- pts/1 (33)
- spire.pdf 破解版 (35)
- shiro jwt (35)
- sklearn中文手册pdf (35)
- itextsharp使用手册 (33)
- 凯立德2012夏季版懒人包 (34)
- 冒险岛代码查询器 (34)
- 128*128png图片 (34)
- jdk1.8.0_131下载 (34)
- dos 删除目录下所有子目录及文件 (36)