Querying average row length in MySQL?


You can use INFORMATION_SCHEMA.TABLES and AVG_ROW_LENGTH to query average row length in MySQL −

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

Let us first create a table −

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

Insert records in the table using insert command −

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)

Display records from the table using select command −

mysql> select *from DemoTable;

This will produce the following output −

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

Query average row length in MySQL −

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

This will produce the following output −

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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

848 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements