Risposte:
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
Questo è mio:
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
AND table_type = 'BASE TABLE'
use databasename;comando. Se il database è molto grande, il comando può essere eseguito con un lungo tempo di attesa. In tal caso, il login dovrebbe essere fatto con l'opzione -A, cioè:, mysql -uroot -p -Ae il comando funzionerà velocemente.
Nel caso in cui desideri un conteggio di tutti i database più un riepilogo, prova questo:
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;
Ecco un esempio:
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)
Provaci !!!
FROMclausola? Perché non solo SELECT IFNULL(table_schema, 'Total') Database, COUNT(*) TableCount FROM information_schema.tables WHERE table_schema NOT IN ('information_schema','mysql') GROUP BY table_schema WITH ROLLUP?
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE'
Questo ti darà nomi e conteggio delle tabelle di tutti i database in te mysql
SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA;
Per contare il numero di tabelle basta fare questo:
USE your_db_name; -- set database
SHOW TABLES; -- tables lists
SELECT FOUND_ROWS(); -- number of tables
A volte le cose facili faranno il lavoro.
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'database_name';
dalla riga di comando:
mysql -uroot -proot -e "select count(*) from
information_schema.tables where table_schema = 'database_name';"
nell'esempio sopra root è username e password, ospitati su localhost.
Spero che questo aiuti e ritorni solo il numero di tabelle in un database
Use database;
SELECT COUNT(*) FROM sys.tables;
sys.tablesnon esiste inmysql
FOUND_ROWS()era maggiore del numero di tabelle restituite quando utilizzavo il primo metodo.