MySQL管理工具MySQL Utilities查询MySQL使用的空间大小

我们准备备份或维护数据的时候,常常会考虑磁盘空间大小的问题,通常需要知道我们的数据和日志有多大,数据是至关重要的,数据是生命线.

使用mysqldiskusage 工具来查看数据库实例使用到的空间,包括数据库和各种日志大小.

实例:

  1. shell> sudo env PYTHONPATH=$PYTHONPATH mysqldiskusage \
  2. --server=root:root@localhost --all
  3. # Source on localhost: ... connected.
  4. # Database totals:
  5. +-----------------+--------------+
  6. | db_name | total |
  7. +-----------------+--------------+
  8. | oltp2 | 829,669 |
  9. | bvm | 15,129 |
  10. | db1 | 9,895 |
  11. | db2 | 11,035 |
  12. | employees | 206,117,692 |
  13. | griots | 14,415 |
  14. | mysql | 995,722 |
  15. | oltp1 | 177,393 |
  16. | room_temp | 9,847 |
  17. | sakila | 791,727 |
  18. | test | 647,911 |
  19. | test_arduino | 9,999 |
  20. | welford_kindle | 72,032 |
  21. | world | 472,785 |
  22. | world_innodb | 829,669 |
  23. +-----------------+--------------+
  24. Total database disk usage = 210,175,251 bytes or 200.44 MB
  25. # Log information.
  26. +--------------------+--------------+
  27. | log_name | size |
  28. +--------------------+--------------+
  29. | host123.log | 957,282,265 |
  30. | host123-slow.log | 123,647 |
  31. | host123.local.err | 321,772,803 |
  32. +--------------------+--------------+
  33. Total size of logs = 1,279,178,715 bytes or 1.19 GB
  34. # Binary log information:
  35. Current binary log file = my_log.000287
  36. +----------------+---------+
  37. | log_file | size |
  38. +----------------+---------+
  39. | my_log.000285 | 252208 |
  40. | my_log.000286 | 256 |
  41. | my_log.000287 | 3063 |
  42. | my_log.index | 48 |
  43. +----------------+---------+
  44. Total size of binary logs = 255,575 bytes or 249.58 KB
  45. # Server is not an active slave - no relay log information.
  46. # InnoDB tablespace information: --phpfensi.com
  47. +--------------+--------------+
  48. | innodb_file | size |
  49. +--------------+--------------+
  50. | ib_logfile0 | 5,242,880 |
  51. | ib_logfile1 | 5,242,880 |
  52. | ibdata1 | 815,792,128 |
  53. | ibdata2 | 52,428,800 |
  54. +--------------+--------------+
  55. Total size of InnoDB files = 889,192,448 bytes or 848.00 MB
  56. InnoDB freespace = 635,437,056 bytes or 606.00 MB

使用–all选项,将显示所有日志和InnoDB的磁盘使用情况,也会列出所有数据库,即使不包含任何数据.

权限:用户必须具有读取数据目录的权限.