文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

列出按大小排序的 MySQL 表和大小?

2023-10-22 10:25

关注

您可以在 information_schema.tables 的帮助下完成此操作。语法如下 -

SELECT TABLE_NAME, table_rows, data_length, index_length,
round(((data_length + index_length) / 1024 / 1024),2) "MB Size"
FROM information_schema.TABLES WHERE table_schema = "yourDatabaseName"
ORDER BY (data_length + index_length) ASC;

为了理解上述语法,让我们为任何数据库实现它。在这里,我使用数据库 TEST。让我们看看数据库 TEST 的查询。

mysql> SELECT TABLE_NAME, table_rows, data_length, index_length,
-> round(((data_length + index_length) / 1024 / 1024),2) "MB Size"
-> FROM information_schema.TABLES WHERE table_schema = "test"
-> ORDER BY (data_length + index_length) ASC;

以下是显示按大小排序的表格的输出。

+------------------------------------+------------+-------------+--------------+---------+
| TABLE_NAME                         | TABLE_ROWS | DATA_LENGTH | INDEX_LENGTH | MB Size |
+------------------------------------+------------+-------------+--------------+---------+
| empinfoview                        | 0          | 0           | 0            | 0.00    |
| lookuptable                        | 0          | 0           | 0            | 0.00    |
| view_student                       | 0          | 0           | 0            | 0.00    |
| empidandempname_view               | 0          | 0           | 0            | 0.00    |
| viewemployeeidandemployeename      | 0          | 0           | 0            | 0.00    |
| customers                          | 0          | 0           | 1024         | 0.00    |
| addingcurrencysymboldemo           | 4          | 16384       | 0            | 0.02    |
| allrecordswithactive               | 6          | 16384       | 0            | 0.02    |
| autostoredatetime                  | 0          | 16384       | 0            | 0.02    |
| bookdatedemo                       | 2          | 16384       | 0            | 0.02    |
| changecurrentautoincrementvalue    | 6          | 16384       | 0            | 0.02    |
| conditionalinsertdemo              | 4          | 16384       | 0            | 0.02    |
| datefromtimestamp                  | 4          | 16384       | 0            | 0.02    |
| decrementdemo                      | 6          | 16384       | 0            | 0.02    |
| differenceinhours                  | 2          | 16384       | 0            | 0.02    |
| fetchrowlasthourdemo               | 6          | 16384       | 0            | 0.02    |
| getfirstdayofmonth                 | 4          | 16384       | 0            | 0.02    |
| increaseanddecreasedemo            | 2          | 16384       | 0            | 0.02    |
| insertingnull                      | 0          | 16384       | 0            | 0.02    |
| isnulldemo                         | 6          | 16384       | 0            | 0.02    |
| newstable                          | 6          | 16384       | 0            | 0.02    |
| nthrecorddemo                      | 6          | 16384       | 0            | 0.02    |
| orderbyrandname                    | 8          | 16384       | 0            | 0.02    |
| pricedemo                          | 4          | 16384       | 0            | 0.02    |
| rowpositiondemo                    | 4          | 16384       | 0            | 0.02    |
| selectdataonyearandmonthdemo       | 4          | 16384       | 0            | 0.02    |
| sortcolumnzeroatlastdemo           | 6          | 16384       | 0            | 0.02    |
| studentdemo                        | 4          | 16384       | 0            | 0.02    |
| sumdemooncolumns                   | 4          | 16384       | 0            | 0.02    |
| tinyintdemo                        | 0          | 16384       | 0            | 0.02    |
| unixtime                           | 2          | 16384       | 0            | 0.02    |
| uppertabledemo                     | 4          | 16384       | 0            | 0.02    |
| wheredemo                          | 4          | 16384       | 0            | 0.02    |
| addingdaysdemo                     | 8          | 16384       | 0            | 0.02    |
| allrows                            | 4          | 16384       | 0            | 0.02    |
| averageontime                      | 4          | 16384       | 0            | 0.02    |
| booldemo                           | 0          | 16384       | 0            | 0.02    |
| changeenginetabledemo              | 0          | 16384       | 0            | 0.02    |
| databystringlength                 | 4          | 16384       | 0            | 0.02    |
| dateinsertdemo                     | 2          | 16384       | 0            | 0.02    |
| defaultdemo                        | 0          | 16384       | 0            | 0.02    |
| differenceinseconds                | 4          | 16384       | 0            | 0.02    |
| employee                           | 2          | 16384       | 0            | 0.02    |
| findlowercasevalue                 | 4          | 16384       | 0            | 0.02    |
| gettinglast5characters             | 4          | 16384       | 0            | 0.02    |
| increasevarchardemo                | 0          | 16384       | 0            | 0.02    |
| insertnulldemo                     | 3          | 16384       | 0            | 0.02    |
| jsonformatdemo                     | 4          | 16384       | 0            | 0.02    |
| lowercasedemo                      | 2          | 16384       | 0            | 0.02    |
| newtableduplicate                  | 3          | 16384       | 0            | 0.02    |
| nullandemptydemo                   | 7          | 16384       | 0            | 0.02    |
| orderbyrelevance                   | 4          | 16384       | 0            | 0.02    |
| primarykey1000demo                 | 4          | 16384       | 0            | 0.02    |
| rowwithsamevalue                   | 4          | 16384       | 0            | 0.02    |
| selectdistincttwocolumns           | 8          | 16384       | 0            | 0.02    |  
| sortingstringdemo                  | 5          | 16384       | 0            | 0.02    |
| studentinformation                 | 5          | 16384       | 0            | 0.02    |
| sumwithifcondition                 | 6          | 16384       | 0            | 0.02    |
| toggledemo                         | 6          | 16384       | 0            | 0.02    |
| unixtimedemo                       | 0          | 16384       | 0            | 0.02    |
| userdateformat                     | 4          | 16384       | 0            | 0.02    |
| wholewordmatchdemo                 | 2          | 16384       | 0            | 0.02    |
| addoneday                          | 2          | 16384       | 0            | 0.02    |
| appendingdatademo                  | 2          | 16384       | 0            | 0.02    |
| base64demo                         | 2          | 16384       | 0            | 0.02    |
| booleandemo                        | 0          | 16384       | 0            | 0.02    |
| charsetdemo                        | 0          | 16384       | 0            | 0.02    |
| convertdatetimetodate              | 4          | 16384       | 0            | 0.02    |
| dateandtimetotimestamp             | 4          | 16384       | 0            | 0.02    |
| daterange                          | 8          | 16384       | 0            | 0.02    |
| deleteallfromtable                 | 0          | 16384       | 0            | 0.02    |
| differencetimestamp                | 2          | 16384       | 0            | 0.02    |
| employeedesignation                | 2          | 16384       | 0            | 0.02    |
| firsttabledemo                     | 2          | 16384       | 0            | 0.02    |
| gmailsignin                        | 4          | 16384       | 0            | 0.02    |
| incrementanddecrementvalue         | 2          | 16384       | 0            | 0.02    |
| insertwithmultipleandsigle         | 21         | 16384       | 0            | 0.02    |
| keywordsearchdemo                  | 6          | 16384       | 0            | 0.02    |
| maxlengthfunctiondemo              | 4          | 16384       | 0            | 0.02    |
| notempty                           | 0          | 16384       | 0            | 0.02    |
| nullatbottom                       | 6          | 16384       | 0            | 0.02    |
| orderindemo                        | 6          | 16384       | 0            | 0.02    |
| proceduredemotable                 | 2          | 16384       | 0            | 0.02    |
| safedeletedemo                     | 4          | 16384       | 0            | 0.02    |
| selectdomainnameonly               | 4          | 16384       | 0            | 0.02    |
| startautoincrement                 | 3          | 16384       | 0            | 0.02    |
| studentmodifytabledemo             | 3          | 16384       | 0            | 0.02    |
| tablealiasdemo                     | 4          | 16384       | 0            | 0.02    |
| toogledemo                         | 6          | 16384       | 0            | 0.02    |
| updatealldemo                      | 2          | 16384       | 0            | 0.02    |
| userrole                           | 4          | 16384       | 0            | 0.02    |
| yesterdaydatedemo                  | 2          | 16384       | 0            | 0.02    |
| agecalculatesdemo                  | 4          | 16384       | 0            | 0.02    |
| autoincrementdemo                  | 6          | 16384       | 0            | 0.02    |  
| betweendatedemo                    | 6          | 16384       | 0            | 0.02    |
| casedemo                           | 2          | 16384       | 0            | 0.02    |
| columnwithspace                    | 4          | 16384       | 0            | 0.02    |
| countingdemo                       | 4          | 16384       | 0            | 0.02    |
| dateasstringdemo                   | 2          | 16384       | 0            | 0.02    |
| datesofoneweek                     | 4          | 16384       | 0            | 0.02    |
| deletedemo                         | 5          | 16384       | 0            | 0.02    |
| differentrows                      | 4          | 16384       | 0            | 0.02    |
| employeeinformation                | 6          | 16384       | 0            | 0.02    |
| firsttablemaxvalue                 | 6          | 16384       | 0            | 0.02    |
| groupbytwofieldsdemo               | 6          | 16384       | 0            | 0.02    |
| incrementby1                       | 6          | 16384       | 0            | 0.02    |
| int11demo                          | 2          | 16384       | 0            | 0.02    |
| lasthourrecords                    | 4          | 16384       | 0            | 0.02    |
| monthdemo                          | 12         | 16384       | 0            | 0.02    |
| notequaldemo                       | 7          | 16384       | 0            | 0.02    |
| onlyhourdemo                       | 3          | 16384       | 0            | 0.02    |
| originaltable                      | 4          | 16384       | 0            | 0.02    |
| queryresultdemo                    | 4          | 16384       | 0            | 0.02    |
| searchdemo                         | 6          | 16384       | 0            | 0.02    |
| sha256demo                         | 0          | 16384       | 0            | 0.02    |
| storedproctable                    | 2          | 16384       | 0            | 0.02    |
| studenttable                       | 3          | 16384       | 0            | 0.02    |
| tableview                          | 0          | 16384       | 0            | 0.02    |
| triggerdemo1                       | 3          | 16384       | 0            | 0.02    |
| updatedate                         | 4          | 16384       | 0            | 0.02    |
| uservariable                       | 2          | 16384       | 0            | 0.02    |
| zipcodepadwithzerodemo             | 4          | 16384       | 0            | 0.02    |
| _student_trackerdemo               | 0          | 16384       | 0            | 0.02    |
| aliasdemo                          | 2          | 16384       | 0            | 0.02    |
| autoincrementdemo1                 | 0          | 16384       | 0            | 0.02    |
| bigintandintdemo                   | 0          | 16384       | 0            | 0.02    |
| caseupdatedemo                     | 4          | 16384       | 0            | 0.02    |
| comparingdate                      | 4          | 16384       | 0            | 0.02    |
| creatingtable                      | 7          | 16384       | 0            | 0.02    |
| datecreatedemo                     | 4          | 16384       | 0            | 0.02    |
| datetimedemo                       | 6          | 16384       | 0            | 0.02    |
| deletemanyrows                     | 2          | 16384       | 0            | 0.02    |
| display                            | 2          | 16384       | 0            | 0.02    |
| employeetable                      | 2          | 16384       | 0            | 0.02    |
| firstworddemo                      | 2          | 16384       | 0            | 0.02    |
| groupmonthandyeardemo              | 4          | 16384       | 0            | 0.02    |
| incrementcounterdemo               | 6          | 16384       | 0            | 0.02    |
| intcurrencydemo                    | 5          | 16384       | 0            | 0.02    |
| lasttwocharacters                  | 2          | 16384       | 0            | 0.02    |
| moviecollectiondemo                | 0          | 16384       | 0            | 0.02    |
| notequalsdemo                      | 5          | 16384       | 0            | 0.02    |
| onlymonthandyear                   | 4          | 16384       | 0            | 0.02    |
| parsedatedemo                      | 4          | 16384       | 0            | 0.02    |
| renameviewdemo                     | 0          | 16384       | 0            | 0.02    |
| searchtextdemo                     | 0          | 16384       | 0            | 0.02    |
| simulatearraydemo                  | 6          | 16384       | 0            | 0.02    |
| stringreplacedemo                  | 2          | 16384       | 0            | 0.02    |
| stuedntinformation                 | 0          | 16384       | 0            | 0.02    |
| tblemployee                        | 0          | 16384       | 0            | 0.02    |
| triggerdemo2                       | 0          | 16384       | 0            | 0.02    |
| updatenumber1to3                   | 3          | 16384       | 0            | 0.02    |
| uservariableinlike                 | 5          | 16384       | 0            | 0.02    |
| _studenttrackerdemo                | 0          | 16384       | 0            | 0.02    |
| allcharacterbeforespace            | 4          | 16384       | 0            | 0.02    |
| autoincrementedprimary             | 4          | 16384       | 0            | 0.02    |
| bigintdemo                         | 0          | 16384       | 0            | 0.02    |
| changecellsdata                    | 4          | 16384       | 0            | 0.02    |
| concatenatetwocolumnsdemo          | 4          | 16384       | 0            | 0.02    |
| creatingtableusingviewstudent      | 0          | 16384       | 0            | 0.02    |
| dateequaltoday                     | 6          | 16384       | 0            | 0.02    |
| dayofweekdemo                      | 6          | 16384       | 0            | 0.02    |
| demo                               | 2          | 16384       | 0            | 0.02    |
| displayint                         | 5          | 16384       | 0            | 0.02    |
| rowexistdemo                       | 4          | 16384       | 0            | 0.02    |
| selectconcat                       | 5          | 16384       | 0            | 0.02    |
| sortbydateandtime                  | 4          | 16384       | 0            | 0.02    |
| sumcasedemo                        | 6          | 16384       | 0            | 0.02    |
| timetoseconddemo                   | 0          | 16384       | 0            | 0.02    |
| union_table2                       | 3          | 16384       | 0            | 0.02    |
| updatewithifcondition              | 2          | 16384       | 0            | 0.02    |
| constraintdemo                     | 0          | 16384       | 16384        | 0.03    |
| insertignoredemo                   | 2          | 16384       | 16384        | 0.03    |
| student                            | 2          | 16384       | 32768        | 0.05    |
+------------------------------------+------------+-------------+--------------+---------+
240 rows in set (22.56 sec)
阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯