Database size calculation?

前端 未结 3 536
说谎
说谎 2020-12-29 12:43

What is the most accurate way to estimate how big a database would be with the following characteristics:

  • MySQL
  • 1 Table with three columns:
    • i
相关标签:
3条回答
  • 2020-12-29 12:57

    My rough estimate works out to: 1 byte for id, 32 bits each for the other two fields.

    You're way off. Please refer to the MySQL Data Type Storage Requirements documentation. In particular:

    • A BIGINT is 8 bytes, not 1.

    • The storage required for a CHAR or VARCHAR column will depend on the character set in use by your database (!), but will be at least 32 bytes (not bits!) for CHAR(32) and 33 for VARCHAR(32).

    • You have not accounted at all for the size of the index. The size of this will depend on the database engine, but it's definitely not zero. See the documentation on the InnoDB row structure for more information.

    0 讨论(0)
  • 2020-12-29 13:02

    On the MySQL website you'll find quite comprehensive information about storage requirements: http://dev.mysql.com/doc/refman/5.6/en/storage-requirements.html

    It also depends if you use utf8 or not.

    0 讨论(0)
  • 2020-12-29 13:15

    If you want to know the current size of a database you can try this:

    SELECT table_schema "Database Name"
         , SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB"
    FROM information_schema.TABLES
    GROUP BY table_schema
    
    0 讨论(0)
提交回复
热议问题