You can use INFORMATION_SCHEMA. TABLES to retrieve information about your database tables. As mentioned in the Microsoft Tables Documentation: INFORMATION_SCHEMA.
MySQL has no limit on the number of tables. The underlying file system may have a limit on the number of files that represent tables. Individual storage engines may impose engine-specific constraints. InnoDB permits up to 4 billion tables.
To get a list of the tables in a MySQL database, use the mysql client tool to connect to the MySQL server and run the SHOW TABLES command. The optional FULL modifier will show the table type as a second output column.
MySQL COUNT() Function The COUNT() function returns the number of records returned by a select query.
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
Source
This is mine:
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
In case you would like a count all the databases plus a summary, please try this:
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 a sample 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 !!!
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE'
To count number of tables just do this:
USE your_db_name; -- set database
SHOW TABLES; -- tables lists
SELECT FOUND_ROWS(); -- number of tables
Sometimes easy things will do the work.
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 COUNT(*) FROM information_schema.tables WHERE table_schema = 'database_name';
There may be multiple ways to count the tables of a database. My favorite is this on:
SELECT
COUNT(*)
FROM
`information_schema`.`tables`
WHERE
`table_schema` = 'my_database_name'
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With