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>

mysql常用快速查询修改操作的更多相关文章

  1. MySQL常用维护命令和操作

    MySQL数据库安装后,除了包括MySQL服务器进程管理外,还提供了大量工具用于管理和维护MySQL服务器的其它工作.下面PHP程序员雷雪松介绍的这些命令都是在MySQL交互界面以外的命令行中执行的. ...

  2. MySQL常用的查询命令

    MySQL常用的查询命令 author: headsen chen   2017-10-19  10:15:25 个人原创.转载请注明作者,出处,否则依法追究法律责任 1,查询现在的时间:mysql& ...

  3. Php mysql 常用代码、CURD操作以及简单查询

    C/S:Client ServerB/S:Brower Server php主要实现B/S LAMP :Linux系统    A阿帕奇服务器    Mysql数据库   Php语言 mysql常用代码 ...

  4. MongoDB查询修改操作语句命令大全

    MongoDB查询更新操作语句命令大全 查询操作 1.条件操作符 <, <=, >, >= 这个操作符就不用多解释了,最常用也是最简单的db.collection.find({ ...

  5. MYSQL初级学习笔记一:MYSQL常用命令和数据库操作(DDL)!(视频序号:初级_3,4)

    知识点一:MYSQL常用命令(3) 登入方法:一,mysql –u 账号 –p 密码 退出方法:一,EXIT,QUIT 修改MYSQL命令提示符: 连接上客户机之后,通常使用prompt命令修改: 连 ...

  6. mysql 数据库 添加查询 修改 删除

    cmd 命令行模式操作数据库 添加查询 修改 删除 ( 表 字段 数据)   一 查看数据库.表.数据字段.数据 1 首先配置环境变量 进入mysql  或者通过一键集成工具 打开mysql命令行   ...

  7. 关于Mysql的高级查询的操作

    前言:作为一名后端的程序员操作数据库的能力是我们基本的技能,而连表查询是我们的这个技能的关键点所在.注意这里顾明思义是对数据的查询的操作 (一).联合查询(关键字union/union all) 什么 ...

  8. 解决mysql表不能查询修改删除等操作并出现卡死

    问题现象1:进程wait卡住 测试环境mysql出现了一个怪表:select查询表卡死,alter修改表卡死,甚至我不想要这个表了,delete.truncate.drop表都卡死卡主了...... ...

  9. MYSQL常用函数以及分组操作

    SELECT CONVERT(",SIGNED); SELECT CAST(" AS SIGNED); SELECT ; SELECT LENGTH("姜浩真帅!&quo ...

随机推荐

  1. B-树 B+树复习总结

    一.B-树的定义 一棵m阶的B-树或为空树,或为具有以下特性的m叉树 1.树中每个结点至多有m棵子树 (m-1个关键字) 2.根结点至少有两棵子树 (至少有一个关键字) 3.除根节点的分支结点至少有f ...

  2. Uncaught SyntaxError: Unexpected token export

    开发过程中遇到这个错误,虽然不影响使用,但是每次浏览器控制台都会有错误输出,看起来十分不舒服,故翻阅资料发现是因为浏览器虽然支持了es6,但是不支持es6的Module直接使用,需要在script标签 ...

  3. django CBV视图源码分析

    典型FBV视图例子 url路由系统 from django.conf.urls import url from django.contrib import admin from luffycity.v ...

  4. Android PowerManager电源管理(Android N )

    ./frameworks/base/core/java/android/os/PowerManager.java该类提供给Application访问电源相关接口. 它的内部类WakeLock是定义的唤 ...

  5. CH2906 武士风度的牛(算竞进阶习题)

    水..... 直接bfs... #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef l ...

  6. 「CodeForces - 717E」Paint it really, really dark gray (dfs)

    BUPT 2017 summer training (for 16) #1H 题意 每个节点是黑色or白色,经过一个节点就会改变它的颜色,一开始在1节点.求一条路径使得所有点变成黑色. 题解 dfs时 ...

  7. Configure new Nagios clients

    安装rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh http:// ...

  8. 洛谷P4907【CYH-01】小奔的国庆练习赛 :$A$换$B$ $problem$(DFS,剪枝)

    洛谷题目传送门 顺便提一下题意有一个地方不太清楚,就是如果输出No还要输出最少需要添加多少张牌才能满足要求.蒟蒻考完以后发现四个点Too short on line 2... 比较需要技巧的搜索 既然 ...

  9. 自学Python4.8-生成器(方式二:生成器表达式)

    自学Python之路-Python基础+模块+面向对象自学Python之路-Python网络编程自学Python之路-Python并发编程+数据库+前端自学Python之路-django 自学Pyth ...

  10. 【BZOJ3142】[HNOI2013]数列(组合计数)

    [BZOJ3142][HNOI2013]数列(组合计数) 题面 BZOJ 洛谷 题解 唯一考虑的就是把一段值给分配给\(k-1\)天,假设这\(k-1\)天分配好了,第\(i\)天是\(a_i\),假 ...