A query to count the number of tables that I have in MySQL

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

+84
mysql
Mar 05 '11 at 1:28
source share
12 answers
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName'; 

Source

It is mine:

 USE databasename; SHOW TABLES; SELECT FOUND_ROWS(); 
+206
Mar 05 2018-11-11T00:
source share

If you want to count all databases and resumes, try the following:

 SELECT IFNULL(table_schema,'Total') "Database",TableCount FROM (SELECT COUNT(1) TableCount,table_schema FROM information_schema.tables WHERE table_schema NOT IN ('information_schema','mysql') GROUP BY table_schema WITH ROLLUP) A; 

Here is an example run:

 mysql> SELECT IFNULL(table_schema,'Total') "Database",TableCount -> FROM (SELECT COUNT(1) TableCount,table_schema -> FROM information_schema.tables -> WHERE table_schema NOT IN ('information_schema','mysql') -> GROUP BY table_schema WITH ROLLUP) A; +--------------------+------------+ | Database | TableCount | +--------------------+------------+ | performance_schema | 17 | | Total | 17 | +--------------------+------------+ 2 rows in set (0.29 sec) 

Give it a try !!!

+23
Mar 05 2018-11-11T00:
source share
 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE' 
+8
Mar 06 '13 at 5:33
source share

To count the number of tables, do the following:

 USE your_db_name; -- set database SHOW TABLES; -- tables lists SELECT FOUND_ROWS(); -- number of tables 

Sometimes light things will do the job.

+2
Aug 19 '16 at 3:50
source share

This will give you the names and number of tables of all the databases in your mysql

 SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA; 
+2
Jan 20 '17 at 5:54 on
source share
 SELECT COUNT(*) FROM information_schema.tables 
+1
09 Sep '14 at 5:48
source share

There are several ways to count database tables. My favorite is:

 SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = 'my_database_name' ; 
+1
Sep 01 '16 at 7:49
source share
 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'; 
+1
Oct 20 '16 at 3:07
source share
 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'database_name'; 
+1
Apr 20 '17 at 12:14
source share

from the command line:

 mysql -uroot -proot -e "select count(*) from information_schema.tables where table_schema = 'database_name';" 

in the above example, root is the username and password hosted on the local hosting.

+1
Apr 23 '17 at 19:38 on
source share

You can use the query below to find the total number of tables in your database.

 select count(*) from information_schema.tables 
+1
Aug 09 '17 at 3:30
source share

We hope this helps, and returns only the number of tables in the database

 Use database; SELECT COUNT(*) FROM sys.tables; 
-one
Jan 24 '12 at 5:22
source share



All Articles