Query your MySQL server for table size by row count and physical size by database

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
After writing a similar SQL procedure to check my table sizes several times, I wrote this stored procedure to check my MySQL database's table size. It will show you the table sizes and row count across all tables in a particular database. I use this to identify any scaling issues with my database and review storage.
Stored procedure
DELIMITER //
CREATE PROCEDURE checkTableSize
(IN tableName VARCHAR(255))
BEGIN
SELECT
table_name AS `Table`,
round(avg(((data_length + index_length) / 1024 / 1024)), 2) as `Size in MB`,
sum(table_rows) as rowCount
FROM information_schema.TABLES where table_schema = tableName
GROUP by table_name
ORDER by rowCount desc;
END //
DELIMITER ;
How to call results
call checkTableSize('EnterDBNameHere');
I'd like to know if there are out-of-the-box solutions from MySQL, or more elegant solutions to my stored procedure. I also thought I'd share in case this helps anyone.
sql mysql database
add a comment |Â
up vote
3
down vote
favorite
After writing a similar SQL procedure to check my table sizes several times, I wrote this stored procedure to check my MySQL database's table size. It will show you the table sizes and row count across all tables in a particular database. I use this to identify any scaling issues with my database and review storage.
Stored procedure
DELIMITER //
CREATE PROCEDURE checkTableSize
(IN tableName VARCHAR(255))
BEGIN
SELECT
table_name AS `Table`,
round(avg(((data_length + index_length) / 1024 / 1024)), 2) as `Size in MB`,
sum(table_rows) as rowCount
FROM information_schema.TABLES where table_schema = tableName
GROUP by table_name
ORDER by rowCount desc;
END //
DELIMITER ;
How to call results
call checkTableSize('EnterDBNameHere');
I'd like to know if there are out-of-the-box solutions from MySQL, or more elegant solutions to my stored procedure. I also thought I'd share in case this helps anyone.
sql mysql database
There's a single row per table, so why do you apply aggregate functions & GROUP BY?
â dnoeth
Jan 29 at 7:39
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
After writing a similar SQL procedure to check my table sizes several times, I wrote this stored procedure to check my MySQL database's table size. It will show you the table sizes and row count across all tables in a particular database. I use this to identify any scaling issues with my database and review storage.
Stored procedure
DELIMITER //
CREATE PROCEDURE checkTableSize
(IN tableName VARCHAR(255))
BEGIN
SELECT
table_name AS `Table`,
round(avg(((data_length + index_length) / 1024 / 1024)), 2) as `Size in MB`,
sum(table_rows) as rowCount
FROM information_schema.TABLES where table_schema = tableName
GROUP by table_name
ORDER by rowCount desc;
END //
DELIMITER ;
How to call results
call checkTableSize('EnterDBNameHere');
I'd like to know if there are out-of-the-box solutions from MySQL, or more elegant solutions to my stored procedure. I also thought I'd share in case this helps anyone.
sql mysql database
After writing a similar SQL procedure to check my table sizes several times, I wrote this stored procedure to check my MySQL database's table size. It will show you the table sizes and row count across all tables in a particular database. I use this to identify any scaling issues with my database and review storage.
Stored procedure
DELIMITER //
CREATE PROCEDURE checkTableSize
(IN tableName VARCHAR(255))
BEGIN
SELECT
table_name AS `Table`,
round(avg(((data_length + index_length) / 1024 / 1024)), 2) as `Size in MB`,
sum(table_rows) as rowCount
FROM information_schema.TABLES where table_schema = tableName
GROUP by table_name
ORDER by rowCount desc;
END //
DELIMITER ;
How to call results
call checkTableSize('EnterDBNameHere');
I'd like to know if there are out-of-the-box solutions from MySQL, or more elegant solutions to my stored procedure. I also thought I'd share in case this helps anyone.
sql mysql database
edited Jan 28 at 22:06
Jamalâ¦
30.1k11114225
30.1k11114225
asked Jan 28 at 16:58
Dom
1263
1263
There's a single row per table, so why do you apply aggregate functions & GROUP BY?
â dnoeth
Jan 29 at 7:39
add a comment |Â
There's a single row per table, so why do you apply aggregate functions & GROUP BY?
â dnoeth
Jan 29 at 7:39
There's a single row per table, so why do you apply aggregate functions & GROUP BY?
â dnoeth
Jan 29 at 7:39
There's a single row per table, so why do you apply aggregate functions & GROUP BY?
â dnoeth
Jan 29 at 7:39
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f186208%2fquery-your-mysql-server-for-table-size-by-row-count-and-physical-size-by-databas%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
There's a single row per table, so why do you apply aggregate functions & GROUP BY?
â dnoeth
Jan 29 at 7:39