Tuesday 6 November 2018

Query to count the number of tables I have in MySQL

I am growing the number of tables I have and I am sometimes curious just to do a quick command line query to count the number of tables in my database. Is that possible? If so, what is the query?

 Answers


SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
This is mine:
USE databasename; 
SHOW TABLES; 
SELECT FOUND_ROWS();



SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE'



This will give you names and table count of all the databases in you mysql
SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA;



select name, count(*) from DBS, TBLS 
where DBS.DB_ID = TBLS.DB_ID 
group by NAME into outfile '/tmp/QueryOut1.csv' 
fields terminated by ',' lines terminated by '\n';



from command line :
mysql -uroot -proot  -e "select count(*) from 
information_schema.tables where table_schema = 'database_name';"
in above example root is username and password , hosted on localhost.



SELECT COUNT(*) FROM information_schema.tables

0 comments:

Post a Comment