ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

如何查看Mysql 库、表大小

2022-08-28 13:32:38  阅读:203  来源: 互联网

标签:四舍五入 查看 Mysql +--------+ mysql 大小 table data round


#1.查看所有数据大小

#1.查询所有数据的大小
mysql> use information_schema;

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
+---------+
| data |
+---------+
| 51.27MB |
+---------+
1 row in set (0.01 sec)

#2.查看指定数据库的大小

mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='world';
+--------+
| data |
+--------+
| 0.58MB |
+--------+
1 row in set (0.00 sec)

 

#3.查看指定数据库的某个表的大小

mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='world' and table_name='city';
+--------+
| data |
+--------+
| 0.39MB |
+--------+
1 row in set (0.00 sec)

 #4.mysql中的round函数

mysql中的round函数和decimal方法使用区别
#1.decimal(10,2),表示最终得到的结果:
整数部分位数+小数部分位数<=10,小数部分位数2,如图示例第一条。
如果保留位数过大,可以使用decimal(13,2)、decimal(15,2)等等。
举个栗子:
select orderid
,driverId
,vipStartTime
,vipEndTime
,case when buy=0 then 0 else cast(actualMoney/buy as decimal(10,2)) end as avg_amount
, month(vipEndTime)-month('2021-02-01 00:00:00') as moncnt
,(case when buy=0 then 0 else cast(actualMoney/buy as decimal(10,2)) end)*( month(vipEndTime)-month('2021-02-28 23:59:59')) as aa

#2、round函数就是返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果,round函数的语法是:ROUND(number,num_digits),即:Round(数值,保留的小数位数)
Number:需要进行四舍五入的数字。
Num_digits:指定的位数,按此位数进行四舍五入。
其中,如果 num_digits 大于 0,则四舍五入到指定的小数位。
如果 num_digits 等于 0,则四舍五入到最接近的整数。
如果 num_digits 小于 0,则在小数点左侧进行四舍五入。
=ROUND(3.19, 1) 将 3.19 四舍五入到一个小数位 (3.2)
=ROUND(2.649, 1) 将 2.649 四舍五入到一个小数位 (2.6)
=ROUND(-5.574, 2) 将 -5.574 四舍五入到两小数位 (-5.57)
=ROUND(18.8, -1) 将 18.8 四舍五入到小数点左侧一位 (20)。这个参数-1表示取整到十位数。

 

标签:四舍五入,查看,Mysql,+--------+,mysql,大小,table,data,round
来源: https://www.cnblogs.com/linuxmysql/p/16632597.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有