如何查詢 MySQL 中的平均行長度?


可以使用 INFORMATION_SCHEMA.TABLES 和 AVG_ROW_LENGTH 查詢 MySQL 中的平均行長度 −

SELECT AVG_ROW_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ‘yourTableName’;

我們首先建立一個表 −

mysql> create table DemoTable
(
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentName varchar(100)
);
Query OK, 0 rows affected (0.90 sec)

使用 insert 命令在表中插入記錄 −

mysql> insert into DemoTable(StudentName) values('John');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable(StudentName) values('Larry');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable(StudentName) values('Sam');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable(StudentName) values('Mike');
Query OK, 1 row affected (0.15 sec)

使用 select 命令顯示錶中的記錄 −

mysql> select *from DemoTable;

這將產生以下輸出 −

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
| 1         | John        |
| 2         | Larry       |
| 3         | Sam         |
| 4         | Mike        |
+-----------+-------------+
4 rows in set (0.00 sec)

查詢 MySQL 中的平均行長度 −

mysql> SELECT AVG_ROW_LENGTH FROM information_schema.tables WHERE TABLE_NAME = 'DemoTable';

這將產生以下輸出 −

+----------------+
| AVG_ROW_LENGTH |
+----------------+
| 4096           |
+----------------+
1 row in set (0.11 sec)

更新日期:2019 年 7 月 30 日

1K+ 瀏覽量

開啟你的 事業

透過完成課程獲得認證

開始
廣告