Skip to content

Instantly share code, notes, and snippets.

@Bivek
Created October 19, 2023 02:03
Show Gist options
  • Save Bivek/332243d78ffcefdcefdb0e00b3b0f3cb to your computer and use it in GitHub Desktop.
Save Bivek/332243d78ffcefdcefdb0e00b3b0f3cb to your computer and use it in GitHub Desktop.
Get all the tables count in MySQL
#STEP1: SET Max lenght according the need
SET group_concat_max_len = 40048;
#STEP2: Execute this to get the query that needs to be executed
SELECT left(tab, length(tab)-6) AS query
FROM (
SELECT GROUP_CONCAT(tab SEPARATOR ' ') AS tab
FROM (
SELECT CONCAT(
'SELECT "',
table_name,
'" AS table_name, COUNT(*) AS exact_row_count FROM `',
table_schema,
'`.`',
table_name,
'` UNION '
) AS tab
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = '<YOUR DATABASE NAME>'
) AS tmp1
) AS tmp2
#STEP3: copy the output from Step#2 and execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment