数据库的大小。 PHP-MySQL

发布于 2024-09-29 12:15:46 字数 67 浏览 1 评论 0原文

我想知道使用 php 的数据库的大小。 如何显示整个数据库的大小(以兆字节为单位)?特定请求的大小(以兆字节为单位)?

I want to know the size of my database using php.
How to display the size in megabytes entire database? Size in megabytes a specific request?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

骑趴 2024-10-06 12:15:46

尝试获取以字节为单位的大小:

mysql_select_db("yourdatabase");  
$q = mysql_query("SHOW TABLE STATUS");  
$size = 0;  
while($row = mysql_fetch_array($q)) {  
    $size += $row["Data_length"] + $row["Index_length"];  
}

然后以兆字节为单位进行转换:

$decimals = 2;  
$mbytes = number_format($size/(1024*1024),$decimals);

Try this to get the size in bytes:

mysql_select_db("yourdatabase");  
$q = mysql_query("SHOW TABLE STATUS");  
$size = 0;  
while($row = mysql_fetch_array($q)) {  
    $size += $row["Data_length"] + $row["Index_length"];  
}

then to convert in megabytes:

$decimals = 2;  
$mbytes = number_format($size/(1024*1024),$decimals);
情徒 2024-10-06 12:15:46
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;
寂寞美少年 2024-10-06 12:15:46

我尝试从互联网来源修改这种情况,请尝试一下。

<?php
mysql_connect("localhost","root","password here"); 
 $namadb=''; //put db name here

 $sql="SELECT table_schema 'db_name', SUM( data_length + index_length) / 1024 / 1024 'db_size_in_mb' FROM information_schema.TABLES WHERE table_schema='$namadb' GROUP BY table_schema ;";
 $query=mysql_query($sql);
 $data=mysql_fetch_array($query); 
 print $data['db_size_in_mb'];

I try to modify from internet source for this case, just try it please.

<?php
mysql_connect("localhost","root","password here"); 
 $namadb=''; //put db name here

 $sql="SELECT table_schema 'db_name', SUM( data_length + index_length) / 1024 / 1024 'db_size_in_mb' FROM information_schema.TABLES WHERE table_schema='$namadb' GROUP BY table_schema ;";
 $query=mysql_query($sql);
 $data=mysql_fetch_array($query); 
 print $data['db_size_in_mb'];
℉服软 2024-10-06 12:15:46

此查询为您提供有关数据库大小的有用数据:

SELECT 
    TABLE_SCHEMA AS DB_Name, 
    count(TABLE_SCHEMA) AS Total_Tables, 
    SUM(TABLE_ROWS) AS Total_Tables_Row, 
    ROUND(sum(data_length + index_length)/1024/1024) AS "DB Size (MB)",
    ROUND(sum( data_free )/ 1024 / 1024) AS "Free Space (MB)"
FROM information_schema.TABLES 
WHERE TABLE_SCHEMA = 'YOUR_DATABASE_NAME'
GROUP BY TABLE_SCHEMA ;

This query give you a useful data about your database size:

SELECT 
    TABLE_SCHEMA AS DB_Name, 
    count(TABLE_SCHEMA) AS Total_Tables, 
    SUM(TABLE_ROWS) AS Total_Tables_Row, 
    ROUND(sum(data_length + index_length)/1024/1024) AS "DB Size (MB)",
    ROUND(sum( data_free )/ 1024 / 1024) AS "Free Space (MB)"
FROM information_schema.TABLES 
WHERE TABLE_SCHEMA = 'YOUR_DATABASE_NAME'
GROUP BY TABLE_SCHEMA ;
昇り龍 2024-10-06 12:15:46

尝试查询information_schema

Try querying information_schema.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文