zoukankan      html  css  js  c++  java
  • mysql常用快速查询修改操作

    mysql常用快速查询修改操作

    一、查找并修改非innodb引擎为innodb引擎

    # 通用操作
    mysql> select  concat('alter table ',table_schema,'.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam'; 

    # 示例
    select
    concat('alter table test.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam';
    mysql> select concat('alter table test.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam';
    +----------------------------------------------------------+
    | concat('alter table test.',table_name,' engine=innodb;') |
    +----------------------------------------------------------+
    | alter table test.tempusermap engine=innodb;              |
    | alter table test.users_relation_list engine=innodb;      |
    +----------------------------------------------------------+
    2 rows in set (0.58 sec)

    mysql>

    二、查询数据大小

    在需要备份数据库里面的数据时,我们需要知道数据库占用了多少磁盘大小,可以通过一些sql语句查询到整个数据库的容量,也可以单独查看表所占容量。

    1、要查询表所占的容量,就是把表的数据和索引加起来就可以了

    mysql>  select TABLE_SCHEMA,(sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024/1024 AS 'size_g' from information_schema.tables where TABLE_SCHEMA NOT IN ('information_schema','mysql','performance_schema')  group by TABLE_SCHEMA;
    +--------------+-----------------+
    | TABLE_SCHEMA | size_g          |
    +--------------+-----------------+
    | db01         | 13.810716629028 |
    | db02         |  0.279693603516 |
    | test         |  0.143768310547 |
    +--------------+-----------------+
    3 rows in set (9.06 sec)

    2、查询所有的数据大小

    select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables; -- 查询所有的数据大小
    mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables; -- 查询所有的数据大小
    +-------------------------------------------------+
    | concat(round(sum(DATA_LENGTH/1024/1024),2),'M') |
    +-------------------------------------------------+
    | 5324.54M                                        |
    +-------------------------------------------------+
    1 row in set (8.60 sec)

    3、查询某个表的数据

    select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from tables where table_schema='test' AND table_name='USER';
    
    mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables where table_schema='test' AND table_name='USER';
    +-------------------------------------------------+
    | concat(round(sum(DATA_LENGTH/1024/1024),2),'M') |
    +-------------------------------------------------+
    | 73.61M                                          |
    +-------------------------------------------------+
    1 row in set (0.03 sec)

    mysql>select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),'M') AS 'SIZE_MB' from information_schema.tables where table_schema='db222' group by table_name order by SIZE_MB asc,table_name asc;
    +----------------+---------+
    | table_name     | SIZE_MB |
    +----------------+---------+
    | t1             | 0.02M   |
    | t_user_partion | 487.33M |
    | t_user_id3     | 71.61M  |
    | t_user_id0     | 74.61M  |
    | t_user_id1     | 74.61M  |
    | t_user_id2     | 74.61M  |
    | t_user_id4     | 74.61M  |
    | t_user_id5     | 74.61M  |
    | t_user_id6     | 74.61M  |
    | t_user_id7     | 74.61M  |
    | t_user_id8     | 74.61M  |
    | t_user_id9     | 74.61M  |
    +----------------+---------+
    12 rows in set (0.00 sec)

    mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') AS table_size,table_name from information_schema.tables where table_schema='fudao_account' AND table_name IN ('db3','db2','db3','db1') group by table_name;
    +------------+------------------------+
    | table_size | table_name             |
    +------------+------------------------+
    | 2.52M      | db1                      |
    | 0.23M      | db2                    |
    | 0.30M      | db3                    |
    +------------+------------------------+
    3 rows in set (0.00 sec)

    mysql>



  • 相关阅读:
    eclipse maven构建的java web工程项目 在修改了工程项目名时,tomcat启动异常java.lang.IllegalArgumentException: Can't convert argument:null
    maven 编译打包时,明明类文件没有问题,却提示错误:未结束的字符串字面值,maven-compiler-plugin:2.3.2
    maven 结合mybaits整合框架,打包时mapper.xml文件,mapper目录打不进war包去问题
    jsp到java后台中文乱码问题
    JVM学习笔记(四):类加载机制
    JVM学习笔记(三):类文件结构
    JVM学习笔记(二):垃圾收集
    内存映像分析工具Eclipse Memory Analyzer
    JVM学习笔记(一):Java内存区域
    Java变量初始化之后的默认值问题
  • 原文地址:https://www.cnblogs.com/bjx2020/p/9103680.html
Copyright © 2011-2022 走看看