Comme @Venkatramanan et d'autres, j'ai trouvé que INFORMATION_SCHEMA.TABLES était peu fiable (en utilisant InnoDB, MySQL 5.1.44), donnant des comptages de lignes différents à chaque fois que je l'exécute même sur des tables en attente. Voici une manière relativement bidouille (mais flexible/adaptable) de générer une grande déclaration SQL que vous pouvez coller dans une nouvelle requête, sans installer de gemmes Ruby et autres.
SELECT CONCAT(
'SELECT "',
table_name,
'" AS table_name, COUNT(*) AS exact_row_count FROM `',
table_schema,
'`.`',
table_name,
'` UNION '
)
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = '**mon_schema**';
Cela produit une sortie comme ceci:
SELECT "func" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.func UNION
SELECT "general_log" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.general_log UNION
SELECT "help_category" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.help_category UNION
SELECT "help_keyword" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.help_keyword UNION
SELECT "help_relation" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.help_relation UNION
SELECT "help_topic" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.help_topic UNION
SELECT "host" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.host UNION
SELECT "ndb_binlog_index" AS table_name, COUNT(*) AS exact_row_count FROM my_schema.ndb_binlog_index UNION
Copiez et collez sauf pour le dernier UNION pour obtenir une belle sortie comme,
+------------------+-----------------+
| table_name | exact_row_count |
+------------------+-----------------+
| func | 0 |
| general_log | 0 |
| help_category | 37 |
| help_keyword | 450 |
| help_relation | 990 |
| help_topic | 504 |
| host | 0 |
| ndb_binlog_index | 0 |
+------------------+-----------------+
8 rows in set (0.01 sec)
3 votes
Réponse étendue qui est également précise pour InnoDB : stackoverflow.com/questions/24707814/…
2 votes
SÉLECTIONNEZ count(table_name) DEPUIS INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'YOUR_DB' donnera le nombre de tables dans votre base de données.