Skip to content

Instantly share code, notes, and snippets.

@matthiasguentert
Last active October 26, 2021 20:02
Show Gist options
  • Save matthiasguentert/c9c089e675794efdbb6e7e7ef99f449c to your computer and use it in GitHub Desktop.
Save matthiasguentert/c9c089e675794efdbb6e7e7ef99f449c to your computer and use it in GitHub Desktop.
MySQL Cheat Sheet

Count all tables in a database

-- Count number of tables 
select count(*)
from information_schema.tables
where table_schema = '<my-schema>'

-- Warning! Might return inaccurate results!
select TABLE_NAME, TABLE_ROWS
from information_schema.tables
where table_schema = '<my-schema>'

-- Count all rows in all tables 
SELECT SUM(TABLE_ROWS) 
     FROM INFORMATION_SCHEMA.TABLES 
     WHERE TABLE_SCHEMA = '<my-schema>';

Show tables in database

show tables;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment