如何查询 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)
广告