Jak można określić, ile miejsca na dysku zajmuje dana tabela MySQL?

Czy istnieje szybki sposób na określenie, ile miejsca na dysku zajmuje dana tabela MySQL? Stół może być MyISAM lub Innodb.

 139
Author: dan, 2011-06-25

8 answers

Dla tabeli mydb.mytable Uruchom to dla:

Bajty

SELECT (data_length+index_length) tablesize
FROM information_schema.tables
WHERE table_schema='mydb' and table_name='mytable';

Kilobajty

SELECT (data_length+index_length)/power(1024,1) tablesize_kb
FROM information_schema.tables
WHERE table_schema='mydb' and table_name='mytable';

Megabajty

SELECT (data_length+index_length)/power(1024,2) tablesize_mb
FROM information_schema.tables
WHERE table_schema='mydb' and table_name='mytable';

Gigabajty

SELECT (data_length+index_length)/power(1024,3) tablesize_gb
FROM information_schema.tables
WHERE table_schema='mydb' and table_name='mytable';

Ogólne

Tutaj jest ogólne zapytanie, gdzie maksymalna Jednostka wyświetlania jest TB (terabajty)

SELECT 
    CONCAT(FORMAT(DAT/POWER(1024,pw1),2),' ',SUBSTR(units,pw1*2+1,2)) DATSIZE,
    CONCAT(FORMAT(NDX/POWER(1024,pw2),2),' ',SUBSTR(units,pw2*2+1,2)) NDXSIZE,
    CONCAT(FORMAT(TBL/POWER(1024,pw3),2),' ',SUBSTR(units,pw3*2+1,2)) TBLSIZE
FROM
(
    SELECT DAT,NDX,TBL,IF(px>4,4,px) pw1,IF(py>4,4,py) pw2,IF(pz>4,4,pz) pw3
    FROM 
    (
        SELECT data_length DAT,index_length NDX,data_length+index_length TBL,
        FLOOR(LOG(IF(data_length=0,1,data_length))/LOG(1024)) px,
        FLOOR(LOG(IF(index_length=0,1,index_length))/LOG(1024)) py,
        FLOOR(LOG(IF(data_length+index_length=0,1,data_length+index_length))/LOG(1024)) pz
        FROM information_schema.tables
        WHERE table_schema='mydb'
        AND table_name='mytable'
    ) AA
) A,(SELECT 'B KBMBGBTB' units) B;
Spróbuj !!!
 276
Author: RolandoMySQLDBA,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-01 14:15:11

To nie będzie dokładne dla tabel InnoDB. Rozmiar na dysku jest w rzeczywistości większy niż zgłoszony przez zapytanie.

Proszę zobaczyć ten link z Percona aby uzyskać więcej informacji.

Http://www.mysqlperformanceblog.com/2008/12/16/how-much-space-does-empty-innodb-table-take/

 10
Author: hs76,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-23 12:20:44

Szybki bit SQL, aby uzyskać 20 największych tabel w MB.

SELECT table_schema, table_name,
  ROUND((data_length+index_length)/POWER(1024,2),2) AS tablesize_mb
FROM information_schema.tables
ORDER BY tablesize_mb DESC LIMIT 20;
Mam nadzieję, że to się komuś przyda!
 9
Author: Ben,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-29 10:35:30

W Linuksie z domyślnie zainstalowanym mysql:

[you@yourbox]$ ls -lha /var/lib/mysql/<databasename>

Na podstawie nixcraft ' s MySQL DB location

 2
Author: geekymartian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-29 20:03:23

Na podstawie odpowiedzi RolandMySQLDBA myślę, że możemy użyć powyższego, aby uzyskać rozmiar każdego schematu w tabeli:

SELECT table_schema, SUM((data_length+index_length)/power(1024,1)) tablesize_kb 
    FROM information_schema.tables GROUP BY table_schema;
Naprawdę mi się podobało!
 1
Author: Arthur Felipe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-30 02:30:38

Mógłbyś spojrzeć na rozmiar plików...

Każda tabela jest przechowywana w kilku osobnych plikach wewnątrz folderu, który ma nazwę niezależnie od nazwy bazy danych. Te foldery są przechowywane w katalogu danych mysql.

Stamtąd można zrobić ' du-sh .* 'aby uzyskać rozmiar tabeli na dysku.

 0
Author: Luke Chadwick,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-24 23:11:43

Pobrane z Jak sprawdzić, ile miejsca na dysku zajmuje moja baza danych?

Możesz sprawdzić rozmiar tabeli MySQL patrząc na phpMyAdmin w Panel sterowania klikając na nazwę bazy danych w lewej ramce i odczytanie wielkości tabel w prawej ramce.

Poniższe zapytanie pomoże również uzyskać te same informacje w bytes

select SUM(data_length) + SUM(index_length) as total_size 
from information_schema.tables 
where table_schema = 'db_name' 
and table_name='table_name';
 0
Author: Rahul,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-09 10:08:30

Użyłbym po prostu Narzędzia' mysqldiskusage ' w następujący sposób

$ mysqldiskusage --server=user:password@localhost mydbname
# Source on localhost: ... connected.

# Database totals:
+------------+----------------+
| db_name    |         total  |
+------------+----------------+
| mydbaname  | 5,403,033,600  |
+------------+----------------+

Total database disk usage = 5,403,033,600 bytes or 5.03 GB
 -1
Author: Natouriano,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-11 07:40:00