{"id":8392,"date":"2019-01-20T14:47:24","date_gmt":"2019-01-20T14:47:24","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=8392"},"modified":"2019-03-09T03:53:06","modified_gmt":"2019-03-09T03:53:06","slug":"how-to-check-mysql-database-tables-size-on-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/20\/how-to-check-mysql-database-tables-size-on-linux\/","title":{"rendered":"How to Check MySQL Database &amp; Tables Size on linux ?"},"content":{"rendered":"<p>MySQL is a Relational Database Management System, widely used as a database system for Linux systems. This article will help you to calculate the size of tables and database in MySQL or MariaDB servers though SQL queries. MySQL stored all the information related to tables in a database in the information_schema database. We will use the information_schema table to find tables and databases size.<b><\/b><\/p>\n<p>How to find each data base size ? Check ALL Databases Size in MySQL using mysql query:<b><\/b><\/p>\n<p>SELECT table_schema AS &#8220;Database&#8221;, SUM(data_length + index_length) \/ 1024 \/ 1024 AS &#8220;Size (MB)&#8221; FROM information_schema.TABLES GROUP BY table_schema;<b><\/b><\/p>\n<p>Sample output:<\/p>\n<p>mysql&gt; SELECT table_schema AS &#8220;Database&#8221;, SUM(data_length + index_length) \/ 1024 \/ 1024 AS &#8220;Size (MB)&#8221; FROM<\/p>\n<p>information_schema.TABLES GROUP BY table_schema<\/p>\n<p>-&gt; ;<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| Database | Size (MB) |<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| information_schema | 0.00878906 |<\/p>\n<p>| mylabdb | 0.00111008 |<\/p>\n<p>| mysql | 0.68704987 |<\/p>\n<p>| performance_schema | 0.00000000 |<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>mysql&gt; SELECT<\/p>\n<p>-&gt; table_schema &#8216;Database Name&#8217;,<\/p>\n<p>-&gt; SUM(data_length + index_length) &#8216;Size in Bytes&#8217;,<\/p>\n<p>-&gt; ROUND(SUM(data_length + index_length) \/ 1024 \/ 1024, 2) &#8216;Size in MiB&#8217;<\/p>\n<p>-&gt; FROM information_schema.tables<\/p>\n<p>-&gt; GROUP BY table_schema;<b><\/b><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/S7qLytR5sqkX55jFV0HD6xaPGsZDulEqQWvNxhj9zZQrRUjMtfRX39FM02zPlUAgroqmgnxKGJJ_e6HKy7sZO6-01rffbOm6ZJ8DepZGj51Y3bvmTbeOerQouFCvEvN0181BHYXf\" width=\"487\" height=\"140\" \/><br \/>\n<b><\/b><\/p>\n<p>Check Single Table Size in MySQL Database<b><\/b><\/p>\n<p>To find out the size of a single MySQL database called mylabdb (which displays the size of all tables in it) use the following mysql query:<b><\/b><\/p>\n<p>mysql&gt; SELECT table_name AS &#8220;Table Name&#8221;,ROUND(((data_length + index_length) \/ 1024 \/ 1024),<\/p>\n<p>2) AS &#8220;Size in (MB)&#8221; FROM information_schema.TABLES WHERE table_schema = &#8220;mylabdb&#8221; ORDER BY (data_length + index_length) DESC;<b><\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/XA8J9ORmbkGq3RyC5yfQQckKgQdpfbRomM99-ZCcyWUjR8HNGyWLzefFeWuJ5Zgd71T-gTalECdBsleT_cDUr2HJcgUhCSIVE8nmTSFMlYZcHWZKSR2bRBl_lKmNAzuOukxfdIcP\" width=\"258\" height=\"80\" \/><br \/>\n<b><\/b>Finally, to find out the actual size of all MySQL database files on the disk (filesystem), run the<\/p>\n<p>du command below.<\/p>\n<p>sudo du -h \/var\/lib\/mysql<b><\/b><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Ft9zAsNWA_HYddqr5R31L0QyrLiNPlmsczEa3cre9vqyVqtwdBoVZ2Q4J7xYmwSIAvrb35DNTHTbo2WpQDKhFWvNZ1v1Ngn904vTA9vfOfmAoUrRPlP4cHPz2FDE2gfQolf65Yph\" width=\"375\" height=\"90\" \/><\/p>\n<p><a href=\"https:\/\/www.linuxforfreshers.com\/2019\/01\/how-to-check-mysql-database-tables-size.html\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL is a Relational Database Management System, widely used as a database system for Linux systems. This article will help you to calculate the size of tables and database in MySQL or MariaDB servers though SQL queries. MySQL stored all the information related to tables in a database in the information_schema database. We will use &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/20\/how-to-check-mysql-database-tables-size-on-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Check MySQL Database &amp; Tables Size on linux ?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8392","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/8392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=8392"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/8392\/revisions"}],"predecessor-version":[{"id":10896,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/8392\/revisions\/10896"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=8392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=8392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=8392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}