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>

复制代码

 



posted @   davie2020  阅读(2527)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示