mysql常用查询信息

  1. 统计当前实例中业务相关的库和表的信息(排除掉mysql sys information_schema
    performance_schema)
    库名 表个数 表名列表
mysql> select table_schema,group_concat(table_name),count(*) from
information_schema.tables where table_schema not in
('sys','mysql','information_schema','performance_schema') group by table_schema;
  1. 统计当前实例每个数据库的数据总量(排除掉mysql sys information_schema
    performance_schema)
select table_schema,sum(table_rows * avg_row_length + index_length)/1024/1024 as
total_mb
from information_schema.tables
where table_schema not in
('sys','mysql','information_schema','performance_schema')
group by table_schema;
  1. 统计当前实例非innodb的表(排除掉mysql sys information_schema performance_schema)
select table_schema,table_name ,engine
from information_schema.tables
where table_schema not in
('sys','mysql','information_schema','performance_schema') and engine <>
'INNODB';
alter table world.aaaaa engine=innodb;
  1. 查询有碎片的表信息
select table_schema,table_name ,data_free
from information_schema.tables
where table_schema not in
('sys','mysql','information_schema','performance_schema')
and data_free >0;
  1. 查询出本地外的连接信息
 select * from information_schema.processlist where host !='locakhost';
  1. 拼接SQL
    a. 查询当前系统中所有非INNODB的表。
select table_schema,table_name ,engine
from information_schema.tables
where table_schema not in
('sys','mysql','information_schema','performance_schema') and engine <>
'INNODB';

b. 将这些非INNODB的表替换为INNODB
8.3.4 TRIGGERS、views、ROUTINES、EVENTS应用
8.3.5 columns
8.3.6 processlist应用

mysql> select concat("alter table ",table_schema,".",table_name,"
engine=innodb;") from information_schema.tables where table_schema not
in ('sys','mysql','information_schema','performance_schema') and engine <>
'INNODB' into outfile '/tmp/alter.sql';
source /tmp/alter.sql
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 修改用户 mysql> alter user root@'localhost' identified by '12...
    不知道就阅读 925评论 0 0
  • 一、MySQL架构与历史 A.并发控制 1.共享锁(shared lock,读锁):共享的,相互不阻塞的 2.排他...
    ZyBlog阅读 19,872评论 3 177
  • 今天看到一位朋友写的mysql笔记总结,觉得写的很详细很用心,这里转载一下,供大家参考下,也希望大家能关注他原文地...
    信仰与初衷阅读 4,750评论 0 30
  • 一、MySQL架构与历史 A.并发控制 1.共享锁(shared lock,读锁):共享的,相互不阻塞的。 2.排...
    阿休阅读 4,684评论 0 37
  • 全书的重点在四五六章:如何建表、如何建索引、如何查询。第一章讲解了一些基本概念:锁与事物隔离 重中之重:4.1数据...
    AbrahamW阅读 1,006评论 0 0