在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

mysql快速查询的方法

142次阅读
没有评论

共计 5307 个字符,预计需要花费 14 分钟才能阅读完成。

自动写代码机器人,免费开通

丸趣 TV 小编给大家分享一下 mysql 快速查询的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

mysql 快速查询的方法:1、查询正在运行中的事务;2、查看当前连接,并且能够知晓连接数;3、查看一个表的大?。?、查看某个数据库所有表的大小。

mysql 快速查询的方法:

1. 查询正在运行中的事务

select p.id,p.user,p.host,p.db,p.command,p.time,i.trx_state,i.trx_started,p.info from information_schema.processlist p,information_schema.innodb_trx i where p.id=i.trx_mysql_thread_id;

2. 查看当前连接,并且能够知晓连接数

select SUBSTRING_INDEX(host,‘:‘,1) as ip , count(*) from information_schema.processlist group by ip;

3. 查看一个表的大小

select concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) from information_schema.tables where table_schema=‘数据库名‘AND table_name=‘表名‘;

4. 查看某个数据库所有表的大小

select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) from information_schema.tables where table_schema=‘t1‘group by table_name;

5. 查看库的大小,剩余空间的大小

select table_schema,round((sum(data_length / 1024 / 1024) + sum(index_length / 1024 / 1024)),2) dbsize,round(sum(DATA_FREE / 1024 / 1024),2) freesize, 
round((sum(data_length / 1024 / 1024) + sum(index_length / 1024 / 1024)+sum(DATA_FREE / 1024 / 1024)),2) spsize 
from information_schema.tables 
where table_schema not in (‘mysql‘,‘information_schema‘,‘performance_schema‘) 
group by table_schema order by freesize desc;

6. 查找关于锁

select r.trx_id waiting_trx_id,r.trx_mysql_thread_id waiting_thread,r.trx_query waiting_query,b.trx_id blocking_trx_id,b.trx_mysql_thread_id blocking_thread,b.trx_query blocking_query 
from information_schema.innodb_lock_waits w 
inner join information_schema.innodb_trx b 
on b.trx_id = w.blocking_trx_id 
inner join information_schema.innodb_trx r on r.trx_id = w.requesting_trx_id\G

information_schema 的使用

1. 查看各个库下的表数据大小

select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) 
from information_schema.tables where table_schema=‘db_name‘group by table_name;

2. 查看各个数据库的数据大小

select TABLE_SCHEMA, concat(round(sum(data_length)/1024/1024,2),‘MB‘) as data_size from information_schema.tables group by table_schema;

3. 查看实例有没有主键

select table_schema,table_name from information_schema.tables 
where (table_schema,table_name) 
not in(select distinct table_schema,table_name from information_schema.STATISTICS where INDEX_NAME=‘PRIMARY‘) 
and table_schema not in (‘sys‘,‘mysql‘,‘information_schema‘,‘performance_schema‘);

4. 查看实例中哪些字段可以为 null

select TABLE_SCHEMA,TABLE_NAME from COLUMNS where IS_NULLABLE=‘YES‘and TABLE_SCHEMA not in (‘information_schema‘,‘performance_schema‘,‘mysql‘,‘sys‘)\G

5. 查看实例中有哪些存储过程和函数

# 存储过程
select ROUTINE_SCHEMA,ROUTINE_NAME,ROUTINE_TYPE
from information_schema.ROUTINES
where ROUTINE_TYPE=‘PROCEDURE‘and ROUTINE_SCHEMA not in (‘mysql‘,‘sys‘,‘information_schema‘,‘performance_schema‘);
select ROUTINE_SCHEMA,ROUTINE_NAME,ROUTINE_TYPE 
from information_schema.ROUTINES 
where ROUTINE_TYPE=‘FUNCTION‘and ROUTINE_SCHEMA not in (‘mysql‘,‘sys‘,‘information_schema‘,‘performance_schema‘);

6. 查看实例中哪些表字段字符集和默认字符集不一致

select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,CHARACTER_SET_NAME 
from information_schema.COLUMNS 
where (CHARACTER_SET_NAME is null or CHARACTER_SET_NAME‘utf8‘) 
and TABLE_SCHEMA not in (‘information_schema‘,‘performance_schema‘,‘test‘,‘mysql‘,‘sys‘);

7. 查看实例中哪些表字段字符校验规则和默认的不一致

查看当前字符集和校对规则设置

show variables like‘collation_%‘;
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,CHARACTER_SET_NAME,COLLATION_NAME 
from information_schema.COLUMNS 
where (COLLATION_NAME is null or COLLATION_NAME‘utf8_general_ci‘) 
and TABLE_SCHEMA not in (‘information_schema‘,‘performance_schema‘,‘test‘,‘mysql‘,‘sys‘);

8. 查看哪些账号有除了 select、update、insert 以外的权限

select GRANTEE,PRIVILEGE_TYPE,concat(TABLE_SCHEMA,‘-‘,TABLE_NAME,‘-‘,COLUMN_NAME) from COLUMN_PRIVILEGES where PRIVILEGE_TYPE not in (‘select‘,‘insert‘,‘update‘)
union 
select GRANTEE,PRIVILEGE_TYPE,TABLE_SCHEMA from SCHEMA_PRIVILEGES where PRIVILEGE_TYPE not in (‘select‘,‘insert‘,‘update‘)
union
select GRANTEE,PRIVILEGE_TYPE,concat(TABLE_SCHEMA,‘-‘,TABLE_NAME) from TABLE_PRIVILEGES where PRIVILEGE_TYPE not in (‘select‘,‘insert‘,‘update‘) 
union
select GRANTEE,PRIVILEGE_TYPE,concat(‘user‘) from USER_PRIVILEGES where PRIVILEGE_TYPE not in (‘select‘,‘insert‘,‘update‘);

9. 查看实例中哪些表不是默认存储引擎,以默认存储引擎为 innodb 为例

select TABLE_NAME,ENGINE 
from information_schema.tables 
where ENGINE!=‘innodb‘and TABLE_SCHEMA not in (‘information_schema‘,‘performance_schema‘,‘test‘,‘mysql‘,‘sys‘);

10. 查看实例中哪些表有外键

select a.TABLE_SCHEMA,a.TABLE_NAME,a.CONSTRAINT_TYPE,a.CONSTRAINT_NAME,b.REFERENCED_TABLE_NAME,b.REFERENCED_COLUMN_NAME 
from information_schema.TABLE_CONSTRAINTS a LEFT JOIN information_schema.KEY_COLUMN_USAGE b 
ON a.CONSTRAINT_NAME=b.CONSTRAINT_NAME where a.CONSTRAINT_TYPE=‘FOREIGN KEY‘;

11. 查看实例中哪些表字段有级联更新

select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,REFERENCED_TABLE_SCHEMA,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME 
from information_schema.KEY_COLUMN_USAGE 
where REFERENCED_TABLE_SCHEMA is not null 
and REFERENCED_TABLE_NAME is not null 
and REFERENCED_COLUMN_NAME is not null and table_schema not in (‘information_schema‘,‘performance_schema‘,‘test‘,‘mysql‘,‘sys‘);

12. 如何根据用户名、连接时间、执行的 sql 等过滤当前实例中的连接信息

select USER,HOST,DB from processlist where TIME

13. 查看数据库中没有索引的表

select TABLE_SCHEMA,TABLE_NAME from information_schema.tables 
where TABLE_NAME not in (select distinct(any_value(TABLE_NAME)) from information_schema.STATISTICS group by INDEX_NAME) 
and TABLE_SCHEMA not in (‘sys‘,‘mysql‘,‘information_schema‘,‘performance_schema‘);

14. 查看数据库中有索引的表,建立了哪些索引

显示结果:库名、表名、索引名

select TABLE_SCHEMA,TABLE_NAME,group_concat(INDEX_NAME) 
from information_schema.STATISTICS where TABLE_SCHEMA not in (‘sys‘,‘mysql‘,‘information_schema‘,‘performance_schema‘) group by TABLE_NAME ;

以上是 mysql 快速查询的方法的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

向 AI 问一下细节

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2024-02-03发表,共计5307字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 少妇无码太爽了不卡视频在线看 | 一本大道加勒比久久综合 | 日本一级毛片免费看 | 亚洲伊人情人综合网站 | 乱码午夜-极国产极内射 | 欧美宗合网 | www久久久久 | 久草免费电影 | 国产一浮力影院 | 福利精品视频 | 免费国产一级特黄久久 | 色婷婷国产精品欧美毛片 | 2019国内精品久久久久久 | 久久国产区 | 99久久精品毛片免费播放高潮 | 国产精品日韩一区二区三区 | 久久精品国产亚洲av果冻传媒 | 中文字幕亚洲欧美日韩高清 | 国产成人一区二区三区在线 | 亚洲精品av无码重口另类 | 在线亚洲自拍 | 久久一区二区三区免费 | 东莞毛片 | 午夜福利一区二区三区在线观看 | 国产区在线看 | 在线毛片网站 | 久久久国产乱子伦精品 | 少妇高潮一区二区三区99 | 日本疯狂爆乳xxxx | 亚洲va欧美va | 欧美日韩国产成人综合在线 | 玖玖视频精品 | 手机看片1024久久香蕉 | 亚洲精品视频在线免费 | 亚洲一区 日韩精品 中文字幕 | 国产资源中文字幕 | 日本草草影院 | 亚洲色图片区 | 国产亚洲美女精品久久久久 | 免费毛片在线看片免费丝瓜视频 | 久久99国产亚洲精品观看 |