Unix和Mysql中列出的数据库大小之间存在差异

前端之家收集整理的这篇文章主要介绍了Unix和Mysql中列出的数据库大小之间存在差异前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我看到db_1的大小时,它只列为4k.但是当我显示db_1的表状态时,我发现根据数据长度,总大小约为3.7 GB.为什么会出现这种差异?另外为什么ibdata1这么大?
drwx------ 2 MysqL MysqL 4.0K Jun  3 08:52 db_1
-rw-r-xr-x 1 MysqL MysqL  22G Jun  3 08:51 ibdata1
drwx------ 2 MysqL MysqL 4.0K Apr 30 22:30 my_DB
drwxr-xr-x 2 MysqL dba   8.0K May  1 12:44 MysqL
-rw-r-xr-x 1 MysqL root  4.4K Jun  1 14:33 
-rw-rw---- 1 MysqL MysqL    5 May 17 18:19 
-rw-r-xr-x 1 MysqL MysqL  51K Jun  3 08:41 
drwxr-xr-x 2 MysqL dba   4.0K Apr 30 22:29 performance_schema







----------------+---------+
| Name                                           | Engine | Version | Row_format | Rows     | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free   | Auto_increment | Create_time         | Update_time | Check_time | Collation         | Checksum | Create_options | Comment |
+------------------------------------------------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-------------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+
| xxxxxxxxxxxxxxxxxxxxxx                         | InnoDB |      10 | Compact    |      117 |            140 |       16384 |               0 |            0 | 17825792000 |           NULL | 2012-05-01 13:24:34 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB |      10 | Compact    |   466203 |            248 |   116015104 |               0 |            0 | 17825792000 |           NULL | 2012-05-01 13:31:28 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      | InnoDB |      10 | Compact    |  1028265 |            111 |   114147328 |               0 |            0 | 17825792000 |           NULL | 2012-05-01 13:32:36 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxxxxxxxx                       | InnoDB |      10 | Compact    |  1353685 |             98 |   133922816 |               0 |            0 | 17825792000 |           NULL | 2012-05-01 13:32:49 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxx                             | InnoDB |      10 | Compact    |    50546 |             52 |     2637824 |               0 |            0 | 17825792000 |           NULL | 2012-05-01 13:04:18 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxxxxxx                         | InnoDB |      10 | Compact    |    44281 |             83 |     3686400 |               0 |            0 | 17825792000 |           NULL | 2012-05-01 13:19:25 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxxxxxxxxx                      | InnoDB |      10 | Compact    |  5841698 |            124 |   729808896 |               0 |    163397632 | 17825792000 |           NULL | 2012-05-01 13:17:29 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
| xxxxxxxxxxxxxxxxxxxxxxxx                       | InnoDB |      10 | Compact    | 52327792 |             60 |  3171942400 |               0 |            0 | 17825792000 |           NULL | 2012-05-03 17:09:41 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
+------------------------------------------------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-------------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+
这是一个很常见的问题.
这是因为您将所有表存储在单个InnoDB文件(ibdata1)中.删除数据后,此文件不会收缩.所以有一点你在你所有的InnoDB表中都存储了22GB的数据,即使你现在可能没那么多.

解决此问题,您需要删除所有InnoDB表,关闭MysqL,删除文件,启动MysqL备份,然后重新导入这些表.

您还可以使用MysqL设置innodb_file_per_table将每个InnoDB表拆分为自己的文件.文件仍然不会自动缩小,但您可以使用alter table … type = innodb发出清理.

猜你在找的Bash相关文章